首頁 >後端開發 >Python教學 >python求斐波那契数列示例分享

python求斐波那契数列示例分享

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-06 11:29:101339瀏覽

代码如下:


def getFibonacci(num):
 res=[0,1]
 a=0
 b=1
 for x in range(0,num):
  if x==a+b:
   res.append(x)
   a,b=b,a+b
 return res

res=getFibonacci(1000)
print(res)

#递归
a=[0,1]
qian=0
def fibna(num,qian):
 print(num)
 he=num+qian
 if he  a.append(he)
  qian=num
  fibna(he,qian)
fibna(1,0)
print(a)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn