Typeerror: a float is required

Asked

Viewed 252 times

0

Good evening. I have the following Python code which, when calculating the variable h, the cited error appears:

x=[]
y=[]
erro=[]
h=[]
x=0.1
y=0.1
for i in range (40):
    x=x**2-0.391*x
    y=y*(y-0.391)
    import math
    erro.append(math.fabs((x-y)/2))
erro.remove(0)
h.append(math.log10(erro)) 
  • 1

    The object erro is a list of 40 positions and you are trying to calculate the log from this list. The function log10 expects a parameter of type float, not a list.

1 answer

0


erro is kind of list and you’re trying to pull log10 from a list.

I made a modification, now it will sweep the list erro and will add each log10 of every bug in the list h. Look how it turned out:

import math
erro=[]
h=[]
x=0.1
y=0.1
for i in range (40):
    x=x**2-0.391*x
    y=y*(y-0.391)
    erro.append(math.fabs((x-y)/2))
erro.remove(0)
for x in erro:
  h.append(math.log10(x)) 

And please, by default, put the import at the code entry.

  • Thanks for the help. When he calculates the log I would like to delete the first 4 values. I tried to put for x in error(4,40): h. append(Math.log10(x)) The following error appeared: 'list' Object is not callable ?

  • Trim the list. h[4:] This command eliminates the first four elements of the final list. And please, if I answered your question, just confirm in the post, it’s important.

  • I have one more problem, could you help me? import numpy as np x=np.ones((4,1)) for k in range (5,45): x[k]=5.5369x[k-1](x[k-2])**2+0.1931*x[k-3] print(x)

  • Just ask a new question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.