# 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(n): #create a list of all fibonacci numbers less than n
    numbers = []
    a = 0
    b = 1
    c = 0
    
    while c < n:
        c = a + b
        numbers.append(c)
        print c
        a = b 
        b = c
    return numbers
    
def add_evens(i): #search through all the values in n and add the even ones
    total = 0
    for j in i:
        if j%2==0:
            total += j
    print total    
        
numbers = fibonacci(4000000)
add_evens(numbers)
