class Fib(object):
def __init__(self,x):
'''
assumes x an int >= 0
'''
assert type(x) == int and x >= 0,\
'Your variable is not an Positive integer!'
self.x = x
def getFib(self):
'''
return Fibonacci of x
'''
if self.x == 0 or self.x == 1:
return 1
else:
return Fib(self.x-2).getFib()\
+ Fib(self.x-1).getFib()
def printFib(self):
'''
print Fibonacci series from 0~x
'''
if self.x == 0:
return [1]
elif self.x == 1:
return [1,1]
else:
Fib_L = []
for i in range(self.x):
Fib_L.append(Fib(i).getFib())
return Fib_L就是Fibonacci 的一个小代码,怎么改到最优啊。
添加回答
举报
0/150
提交
取消