您的位置:首页 > 其它

Project Euler - Problem 2

2012-05-05 07:46 239 查看
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 SumOfEvenValuedFibbonacciTerms(limit):
sum = 0
a = b = 1
while b < limit:
if not b % 2:
sum += b
a, b = b, a + b
return sum
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: