The Fibonacci series of integers was orignally used in biology to predict the population increase of rodents, or the branching of the veins in a leaf (top to stem).
A Fibonacci number series is made by adding the current number to the previous number to get the next mumber. According to http://en.wikipedia.org/wiki/Fibonacci_number the series starts with 0, 1
This is one of the fastest ways to calculate the Fibonacci series:
def fibo3( n ):
(current, previous) = (0, 1)
k = n
while k > 0:
# use a tuple swap
(current, previous) = (previous, current + previous)
k -= 1
return current
for n in range(13):
print fibo3(n),
"""
example output:
0 1 1 2 3 5 8 13 21 34 55 89 144
"""
This is probably the sweetest way to create a list of the series:
fibo_list = [0,1]
for n in range(input('Enter an integer (>0): ')-1):
fibo_list.append(fibo_list[-2] + fibo_list[-1])
print fibo_list
"""
example output:
Enter an integer (>0): 12
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
"""
Note: changed php code field tags, don't work properly any more.