1. 程式人生 > >求斐波拉契數列——python

求斐波拉契數列——python

數列個數自定義 程式碼展示:

n=int(input('求斐波拉契數列的個數?'))
list=[]
for m in range(0,n):
    if m==0:
        list.append(0)
    elif m==1:
        list.append(1)
    else:
        list.append(list[m-1]+list[m-2])
for i in range(len(list)):
    print(list[i],end=' ')

執行結果: 求斐波拉契數列的個數?15 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377