Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7c5573f6b4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 21 lines (18 sloc) 0.494 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/python
#filename euler2.py


def sum_fibonacci_upto_this(maxValue):
    firstTerm = 1
    secondTerm = 2
    nextTerm = 0
    sum = secondTerm
    while True:
        nextTerm = firstTerm + secondTerm
        if(nextTerm > maxValue):
            break
        if nextTerm % 2 == 0:
            sum += nextTerm
        firstTerm = secondTerm
        secondTerm = nextTerm
    print "Sum is %d" % sum
if __name__ == "__main__":
    sum_fibonacci_upto_this(4000000)
Something went wrong with that request. Please try again.