0, 1,1,2,3,5,8,13,21,34,55,89,144………..
The first two numbers are 0,1 or other chosed start point, and the subsequent number is the sum of the two previous numbers.
Here is the script:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 6 09:30:30 2015
@author: yuan
"""
class recursion:
def __init__(self):
self.arr=[0]
def Fibonacci_1(self, a, b, product): #startpoint is a and b
self.arr.append(b)
if b>=product:#endpoint is product
return self.arr
else:
return self.Fibonacci_1(b,a+b, product) #recursive condition
def export(self):
print self.arr
return self.arr
#main programming
r=recursion();
#the output shuld like that
#0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233……
#common programming
r.Fibonacci_1(0,1, 10000)
Fibonacci=r.export()
No comments:
Post a Comment