1. 程式人生 > >Python 遞歸實現斐波那契數列

Python 遞歸實現斐波那契數列

斐波那契數列

Python 遞歸實現斐波那契數列


def fab(n):

if n==1 or n==2:

return 1

else:

return fab(n-1)+fab(n-2)

num=int(input(‘請輸入數字:‘))

result=fab(num)

print("總共有%d個小兔子"% result)


本文出自 “13361631” 博客,請務必保留此出處http://13371631.blog.51cto.com/13361631/1983959

Python 遞歸實現斐波那契數列