斐波那契数列Python编程

斐波那契数列可以用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 r

你可能感兴趣的:(python,开发语言)