Jupyter Notebook
in_put = input(">>")
nInPut = int(in_put)#输入n,求斐波那契数列前n项
x1 = 1 # x-1
x2 = 1 # x-2
i = 1
count = 2
print('1 1',end=' ')
while count < nInPut:
if i == (x1 + x2): #f(x)=f(x-1)+f(x-2)
x2 = x1
x1 = i
count += 1
print(i,end=' ')
# if count == nInPut:
# print(i ,end = ' ') # 只输出第n项用
i += 1
>>25
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025