斐波那契数列Python编程
时间: 2023-05-21 13:02:28 浏览: 65
斐波那契数列可以用Python编程来实现,代码如下:
def fibonacci(n):
a = 0
b = 1
if n < 0:
print("Incorrect input")
elif n == 0:
return a
elif n == 1:
return b
else:
for i in range(2,n):
c = a + b
a = b
b = c
return b
# 调用函数
print(fibonacci(9))
阅读全文