Project Euler: Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 0 and 1, the first 12 terms will be:

0, 1, 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.


In [7]:
# YOUR CODE HERE
fibbs = [0,1]
summ =0
for x in range(2,34):
    fibbs.append(fibbs[x-1]+fibbs[x-2])

    
for a in fibbs:
        if a%2 == 0 and a <4000000 :
            summ +=a

print(summ)


4613732

In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.