Why does this piece of code not generate fibonacci numbers less than the set value.
from math import sqrt
def Fib(n):
return round(((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5)))
def Fiblessthan(m):
total = [0]
count = 1
while max(total) < m:
total.append(Fib(count))
count = count + 1
For example i won't it to be able to print all the fibonacci numbers less than 4000000. Is this the right way to approach this.
you have to check for length of total less than m.