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 [3]:
#I worked with James Amarel
series = [0,1]
x=0
#loop checks that sum of last two numbers in series are less than 4 mil
while series[x]+series[x+1] <= 4000000:
    #appends sum of previous two consecutive numbers in sereis to series
    series.append(series[x]+series[x+1])
    #redefines x as the next entry in series
    x = x+1

In [5]:
print(sum(i for i in series if i%2==0))


4613732

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