'''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.'''

term1 = 1
term2 = 2
fib_num = 0
even_valued_sum = 2

while fib_num < 4000000:
    fib_num = term1 + term2
    term1 = term2
    term2 = fib_num

    # Now, the sum of the even-valued terms
    if fib_num % 2 == 0:
        even_valued_sum += fib_num

print 'Sum of even valued terms =', even_valued_sum

# Answer = 4613732