首页 > 其他 > 详细

Problem 2

时间:2019-05-31 19:33:42      阅读:118      评论:0      收藏:0      [点我收藏+]
# Problem_2.py
"""
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
"""
def fibonacci(x=1, y=1, end=10000):
    if x >= end:
        return []
    else:
        return [x] + fibonacci(y, x+y, end)


fib = fibonacci(end=4000000)
print(fib)
num = sum([i for i in fib if i%2==0])
print(num)

 

Problem 2

原文:https://www.cnblogs.com/noonjuan/p/10956931.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!