Skip to content

Instantly share code, notes, and snippets.

@pyplacca
Created February 9, 2018 13:12
Show Gist options
  • Save pyplacca/c723b2098f64ad2e96867532100388ce to your computer and use it in GitHub Desktop.
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'.
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