首页 > 编程语言 > 详细

python fibonacci recursion review

时间:2017-02-20 11:30:47      阅读:216      评论:0      收藏:0      [点我收藏+]

 

lis=[]
def fib(depth):
    # if depth==0:
    #     a1=0
    #     a2=1
    #     a3=a1+a2
    # elif depth==1:
    #     a1=1
    #     a2=1
    #     a3=a1+a2
    # else:
    #     fib(depth)= fib(depth-2) + fib(depth-1)
    # lis.append(fib(depth))
    # a1=0
    # a2=1
    # a3=a1+a2
    if depth==1:
        return 0
    elif depth==2:
        return 1
    else:
        return fib(depth-1)+fib(depth-2)
    # else:
    #     fib(depth)=fib(depth-1)+fib(depth-2)
    #     return fib(depth)
    # elif depth==2:
    #     fib(2)=a2
    # elif depth==3:
    #     fib(depth)=a1+a2
    # return lis
try:
    d=int (input(‘please enter decimal as depth: ‘))
except ValueError:
    d=1
# print(fib(depth)
for i in  range(1,d+1):
    lis.append(fib(i))
print(lis)

  

 

python fibonacci recursion review

原文:http://www.cnblogs.com/ezway/p/6418347.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!