Skip to content

Instantly share code, notes, and snippets.

@BedirYilmaz
Last active October 19, 2016 07:38
Show Gist options
  • Save BedirYilmaz/f084dc3dd24351979dcd2a94798b1bf2 to your computer and use it in GitHub Desktop.
Save BedirYilmaz/f084dc3dd24351979dcd2a94798b1bf2 to your computer and use it in GitHub Desktop.
Sum of the even fibonacci numbers that are smaller than 4000000
def fib (n) :
if (n == 1 or n==2):
return 1
return (fib(n-1) + fib(n-2))
limit = 4000000
x = 1
sum = 0
a = 0
while a < limit:
a = fib(x)
x += 1
if a % 2 == 0 :
sum += a
print( " sum of the even fibonacci numbers that are smaller than 4000000 is " + str(sum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment