Created
February 9, 2018 13:12
-
-
Save pyplacca/c723b2098f64ad2e96867532100388ce to your computer and use it in GitHub Desktop.
The function returns the sum of all even numbers in the Fibonacci series whose values do not exceed 'n'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibEvens(n): | |
fibs = [] | |
fib_evens = [] | |
a,b = 0,1 | |
while b < n: | |
a,b = b,a+b | |
if b < n: | |
fibs.append(b) | |
for numbers in fibs: | |
if numbers % 2 == 0: | |
fib_evens.append(numbers) | |
return sum(fib_evens) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment