#!/usr/bin/python2
"""
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.
"""
odd, even = 0,1
total = 0
while True:
odd = odd + even #Odd
even = odd + even #Even
if even < 4000000:
total += even
else:
break
print total
Мой алгоритм:
even
больше 4e6, я выхожу из бесконечного цикла. Я столько всего перепробовал, но мой ответ всегда неправильный. Гугление говорит, что ответ должен быть 4613732
, но я всегда получаю 5702886
Спасибо за поддержку.