Project Euler

Problem 2: Even Fibonacci Numbers

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. Run this solution at repl.io here.

      
        a, b = 1, 1
        fib_sum = 0

        while b < 4000000:
          a, b = b, a + b
          if b % 2 == 0:
            fib_sum += b

        print(fib_sum)
      
    

back to code menu