Fibonacci numbers in Python
Example for versions
Python 2.5.2,
Python 2.6.5
This example uses recursive definition of Fibonacci numbers.
#! /usr/bin/env python
def fibonacci(n):
if n < 3:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
for n in range(1, 16 + 1):
print "%i," % fibonacci(n) ,
print "..."
Comments
]]>blog comments powered by Disqus
]]>