python newbie——PE No.2

斐波那契数列中的每一项被定义为前两项之和。从1和2开始,斐波那契数列的前十项为:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

考虑斐波那契数列中数值不超过4百万的项,找出这些项中值为偶数的项之和。

list = [1, 2]
temp = 3
while temp <= 4000000:
    list.append(temp)
    temp = sum(list[-2::])
print sum(list[1::3])

<<<

4613732

原文地址:https://www.cnblogs.com/mymma/p/2999764.html