TypeError: a float is required

0

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

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)) 
    
asked by anonymous 29.09.2017 / 01:58

1 answer

0

erro is list type and you are trying to pull log10 from a list.

I made a modification, now it will scan the erro list and will add every log10 of each error in the h list. Here's how it went:

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 import in the code entry.

    
29.09.2017 / 02:10