Python/project_euler/problem_02/sol2.py
2019-02-10 00:59:43 +08:00

16 lines
361 B
Python

def fib(n):
"""
Returns a list of all the even terms in the Fibonacci sequence that are less than n.
"""
ls = []
a, b = 0, 1
while b < n:
if b % 2 == 0:
ls.append(b)
a, b = b, a+b
return ls
if __name__ == '__main__':
n = int(input("Enter max number: ").strip())
print(sum(fib(n)))