#背景介绍
Fibonacci数列与以下概念相关:
1.黄金分割
2.递归算法
3.自然现象
#程序代码
-- coding: utf-8 --
“”"
Created on Tue Jan 7 10:32:48 2020
@author: James
“”"
def fibo(n):
if n <= 1:
return n
else:
return(fibo(n-1)+fibo(n-2))
def ptrFibo(n):
for i in range(n):
print(fibo(i+1))
#test
def test():
print(‘Print the first to the tenth items of Fibonacci Sequence:’)
ptrFibo(10)
if name == ‘main’:
test()
调用和以前的程序差不多
#谢谢大家