用户输入指定的数列范围,正确输出结果。
源代码:
def fiebo(n):
a = 1
b = 1
for i in range(n):
if i == 0:
print(a, end=" ")
elif i == 1:
print(b, end=" ")
else:
c = a + b
a = b
b = c
print(c, end=" ")
ww = int(input("需要输出几位斐波那契数列?\n"))
fiebo(ww)
列出测试数据和实验结果截图: