使用函数递归的方法打印斐波那契数列的前 n 个数:0 1 1 2 3 5 8 13 21 34 …… 找出正确的选项。
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
def print_fib(n):
for i in range(n):
print(fib(i), end=" ")
print_fib(10)
输出结果为:0 1 1 2 3 5 8 13 21 34
原文地址: https://www.cveoy.top/t/topic/bL2c 著作权归作者所有。请勿转载和采集!