如何创建包含下面创建的fibonnaci系列的输出值的列表?
a,b=1,2
print(a)
while b<4000000:
print(b)
a,b=b,a+b
要保持最小的更改,只需在循环之前初始化一个列表,然后在每次计算数字时都将其追加。
numbers = []
a,b = 1,2
while b < 4000000:
numbers.append(a)
a,b = b,a + b
numbers.append(a) #Get that last number after you calculated it last time