【发布时间】:2022-01-04 14:17:00
【问题描述】:
我是一名学生,刚接触 python。我正在尝试编写一个程序来判断用户输入的数字是否为斐波那契。
num=int(input("Enter the number you want to check\n"))
temp=1
k=0
a=0
summ=0
while summ<=num:
summ=temp+k
temp=summ
k=temp
if summ==num:
a=a+1
print("Yes. {} is a fibonnaci number".format(num))
break
if a==0:
print("No. {} is NOT a fibonacci number".format(num))
#The program is working for only numbers upto 2.
【问题讨论】:
-
欢迎来到stackoverflow。请阅读stackoverflow.com/help/how-to-ask。
-
你的问题是什么?
-
k=temp紧跟在temp=summ之后,所以k和temp是同一个数字,而不是您想要的最后两个斐波那契数。