Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # to define the nth fibonacci number
- def fibonacci(n):
- if n == 1:
- return 1
- elif n == 0:
- return 0
- else:
- return fibonacci(n-1) + fibonacci(n-2)
- fiblist = [] #this will contain all the fibonacci numbers I need
- for i in range(35): # random guess as to which fib number is about 4 million
- if fibonacci(i) > 4000000:
- break
- else:
- fiblist.append(fibonacci(i))
- total = 0 # will give me my result
- for x in fiblist: # checks whether each number is even or not
- if x % 2 == 0:
- total += x
- print (total)
- input("Press Enter to exit.")
Advertisement
Add Comment
Please, Sign In to add comment