pythonbook/Python 基础教程/1.5.7 A 练习1.py

18 lines
272 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1.有一分数序列2/13/25/38/513/821/13…求出这个数列的前20项之和。
from functools import reduce
# A 构建list
a = 2
b = 1
l = [a/b]
for i in range(1,20):
a,b = a+b,a
l.append(a/b)
print(l)
print(reduce(lambda x,y:x+y,l))