使用函数求前20个斐波那契数列:
斐波那契数列:1,1,2,3,5,8,13,21…
即: 起始 两项均为1,此后的项分别为前两项之和
def feibo(num):
a, b = 1, 1
list1 = []
for i in range(num):
if i == 0:
list1.append(a)
else:
a, b = b, a+b
list1.append(a)
print(list1)
return list1
feibo(20)