Fibonacci: How to think recursively

Mike hennebry at
Wed Sep 1 19:31:27 CEST 2010

The most straightforward method would be to apply the formula
Loop on j computing Fj along the way
if n<=1 : return n

for j in range(2,n) :
    Fold, Fnew = Fnew, Fold+Fnew
return Fnew

Even simpler:
return round(((1+sqrt(5.))/2)**n/sqrt(5.))

More information about the Python-list mailing list