第一种:递归法
def fibo(n):
if n < 3:
return 1
return fibo(n-1) + fibo(n-2) print(fibo(6))
第二种:循环
def fibo1(n):
a, b = ,
for i in range(n):
a, b = b, a+b
return a print(fibo1())
第三种:生成器
def fibo2(n):
a, b = ,
while n:
yield a
a, b = b, a+b
n -= for i in fibo2():
print(i)