Project Euler #2 Summing Fibonacci

Project euler #2

Testing out "" , a plugin that allows you to blog with Jupyter notebooks.

Problem definition

Project Euler #2 "", By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

By using a loop (and not a recursive function) we avoid the only pit fall here, calculating the answer in very short time.

In [10]:
f1 = 0
f2 = 1
s = 0

while f2 < 4*10**6:
    f1,f2 = f2, f1+f2
    if f2%2 == 0:
        s+= f2