Project Euler #2: Even Fibonacci numbers

  • + 0 comments
    defining a function to check the given condition

    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)