Project Euler 2-Even Fibonacci numbers

Even Fibonacci numbers

Problem 2

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.

Answer:
4613732
Completed on Fri, 5 Apr 2013, 06:37

Go to the thread for problem 2 in the forum.

 Even(是偶数的意思……(─.─|||

f=[1,1,1]
i=2
ans=0
while f[i]+f[i-1]<4000000:
i=i+1
f.append(f[i-1]+f[i-2])
if (f[i]%2==0): ans=ans+f[i]
print sum(f)-1,f,ans