下面是自己写着玩的:
a=1
b=1
temp=int(input(“输入第几个数:”))
if temp == 1:
print(“第”,temp,“个数是”,0)
elif temp2 or temp3:
print(“第”,temp,“个数是”,1)
else:
for i in range(temp-3):
sum=a+b
a=b
b=sum
print(“输出第”,temp,“个数是:”,b)
================================================================================菜鸟网站上的例子
nterms = int(input(“你需要几项?”))
n1 = 0
n2 = 1
count = 2
if nterms <= 0:
print(“请输入一个正整数。”)
elif nterms == 1:
print(“斐波那契数列:”)
print(n1)
else:
print(“斐波那契数列:”)
print(n1,",",n2,end=" , “)
while count < nterms:
nth = n1 + n2
print(nth,end=” , ")
# 更新值
n1 = n2
n2 = nth
count += 1
执行以上代码输出结果为:
下面是网友的总结:
https://www.cnblogs.com/areyouready/p/8979973.html
https://www.cnblogs.com/panlq/p/9307203.html
https://www.runoob.com/python3/python3-fibonacci-sequence.html