I defined a function to calculate fibonacci numbers which works well.
Now I'm trying to add up all the even numbered fibonacci numbers <= n than are also <= 4000000 but I'm getting no output.
def fib_iterative(n):
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return a
def sum_even_fibs(n):
total = 0
n = 0
while fib_iterative(n) < 4000000:
if fib_iterative(n) % 2 == 0:
total += fib_iterative(n)
n += 1
return total
print(sum_even_fibs(10))
# 1,1,2,3,5,8,13,21,34,55.
# 2 + 8 + 34 = 44