#n参数表示几个数
def fibonacci(n):
a,b,counter=0,1,2
c=[0,1]
while counter < n:
a, b = b, a + b
c.append(b)
counter += 1
return c
f=fibonacci(10)
print(f)
结果:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
#n参数表示几个数
def fibonacci(n):
a,b,counter=0,1,2
c=[0,1]
while counter < n:
a, b = b, a + b
c.append(b)
counter += 1
return c
f=fibonacci(10)
print(f)
结果:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]