#
'''
Project Euler - Problem 2 - Even Fibonacci numbers
https://projecteuler.net/problem=2

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.

Task: Sum Even Fibonacci terms under four million
'''

import sys

def gen_even_fibo(prev_num=1, number=1, limit=100):
    """Generate a continuous series of Even Fibonacci numbers upto limit value

    Since the results are not to exceed limit, the generated is seeded with the
    first output number (1) and yeild immediately. On next gen, the new result
    is calculated and only yeilded if the while holds true
    """
    while number < limit:
        if number % 2 == 0:
            # only yeild even numbers
            yield number
        prev_num, number = number, prev_num + number

def main():
    '''Sum Even Fibonacci terms under four million
    '''
    result = sum(gen_even_fibo(limit=4000000))
    print("Sum Even Fibonacci terms under four million: "
          "{0}".format(result))


if __name__ == '__main__':
    # interactive run main, capture keyboard interrupts
    try:
        sys.exit(main())
    except KeyboardInterrupt:
        pass

Add problem 2 even fibonacci numbers python solution
Add problem 2 even fibonacci numbers python solution
