# https://projecteuler.net/problem=2 # Sum the even Fibonacci terms not exceeding 4,000,000. # Recursive function calling, generators and Python idioms def fib(): a, b = 1, 2 while True: yield a a, b = b, a + b def evens(it): for x in it: if x % 2 == 0: yield x def upto(limit, it): for x in it: if x > limit: return yield x def euler2(limit=4000000): return sum(evens(upto(limit, fib()))) print(euler2())