Guest User

Untitled

a guest
Jul 19th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # to define the nth fibonacci number
  2. def fibonacci(n):
  3.     if n == 1:
  4.         return 1
  5.     elif n == 0:
  6.         return 0
  7.     else:
  8.         return fibonacci(n-1) + fibonacci(n-2)
  9.  
  10. fiblist = [] #this will contain all the fibonacci numbers I need
  11.  
  12. for i in range(35): # random guess as to which fib number is about 4 million
  13.     if fibonacci(i) > 4000000:
  14.         break
  15.     else:
  16.         fiblist.append(fibonacci(i))
  17.      
  18.  
  19. total = 0 # will give me my result
  20.  
  21. for x in fiblist: # checks whether each number is even or not
  22.     if x % 2 == 0:
  23.         total += x
  24.  
  25.  
  26. print (total)
  27.  
  28. input("Press Enter to exit.")
Advertisement
Add Comment
Please, Sign In to add comment