You are viewing a single comment's thread. Return to all comments →
def sum_fib(n): a,b= 1,2 even_sum = 0 while b<=n: if b%2==0: even_sum +=b a,b=b,a+b return even_sum
if name == 'main': t = int(input().strip())
for t_itr in range(t): n = int(input().strip()) res = sum_fib(n) print(res)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
def sum_fib(n): a,b= 1,2 even_sum = 0 while b<=n: if b%2==0: even_sum +=b a,b=b,a+b return even_sum
if name == 'main': t = int(input().strip())