斐波那契数列Python编程
时间: 2023-11-19 16:26:52 浏览: 11
斐波那契数列可以用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))
阅读全文