Problem 2

来源:互联网 发布:手机怎样删除淘宝差评 编辑:程序博客网 时间:2024/05/05 00:15
# -*- coding = utf-8 -*-#!/usr/bin/python'''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 valuesdo not exceed four million, find the sum of the even-valued terms.'''def Fibonacci ():    x = 1    y = 1    sum = 0    while (x < 4000000):        if( x % 2 == 0):            sum = sum + x        x, y = y , x + y    print "sum = %d" %(sum)        if __name__ == '__main__':    Fibonacci()


0 0