python编程练习---拉斐波器数列
拉斐波器数列的实现:
代码:
fibs=[0,1]
n=int(input("请输入数列长度"))
for i in range(0,n-2):
fibs.append(fibs[-2]+fibs[-1])
print(fibs)
运行截图:
编写成函数
代码:
def fibs(n):
fib=[0,1]
for i in range(0,n-2):
fib.append(fib[-2]+fib[-1])
return fib
a=int(input("请输入是数列长度:"))
Fibs=fibs(a)
print("拉斐波器数列为:",Fibs)
运行截图: