def fibo(n):
if n <= 1:
return n
else:
return (fibo(n-1)+fibo(n-2))
number = int(input("输出几位斐波那契数列?"))
if number <= 0:
print("输入正数")
else:
print("斐波那契数列:")
for i in range(number):
print(fibo(i))
非递归:
def fibo(n):
a = [0,1]
for i in range(n-2):
a.append(a[-2]+a[-1])
return a
print(fibo(10))
递归:def fibo(n):if n <= 1: return nelse: return (fibo(n-1)+fibo(n-2))number = int(input("输出几位斐波那契数列?"))if number <= 0: print("输入正数")else: print("斐波那契数列:") for i in rang...