Return to Snippet

Revision: 58488
at July 18, 2012 03:41 by akus85


Initial Code
"""
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.
"""

l = [1,1]
x = 1
while (x <= 4000000):
	x = l[len(l)-1]+l[len(l)-2]
	l.append(x)
print sum([i for i in l if(i%2==0)])

Initial URL


Initial Description


Initial Title
[Project Euler] Exercise 02

Initial Tags


Initial Language
Python