Python 实训1 计算出斐波那契数列前两项给定长度的数列,并删除重复项和追加数列各项之和为新项
程序员文章站
2022-04-02 10:40:51
...
源码:
def Fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return Fibonacci(n - 1) + Fibonacci(n - 2)
def Fibonacci_Recursion(n):
result_list = [0,1]
for i in range(2, n + 1):
result_list.append(Fibonacci(i))
result_list.pop(2)
list_sum = sum(result_list)
print("列表数据之和=%d"%list_sum)
return result_list
print("列表=%s"%Fibonacci_Recursion(5))
答案送你啦,拿到答案点个赞呗~