2018-10-19 07:48:28 -05:00
|
|
|
def fib(n):
|
2019-02-09 10:59:43 -06:00
|
|
|
"""
|
|
|
|
|
Returns a list of all the even terms in the Fibonacci sequence that are less than n.
|
|
|
|
|
"""
|
|
|
|
|
ls = []
|
|
|
|
|
a, b = 0, 1
|
2018-10-19 07:48:28 -05:00
|
|
|
while b < n:
|
2019-02-09 10:59:43 -06:00
|
|
|
if b % 2 == 0:
|
|
|
|
|
ls.append(b)
|
2018-10-19 07:48:28 -05:00
|
|
|
a, b = b, a+b
|
2019-02-09 10:59:43 -06:00
|
|
|
return ls
|
2018-10-19 07:48:28 -05:00
|
|
|
|
2019-02-09 10:59:43 -06:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
n = int(input("Enter max number: ").strip())
|
|
|
|
|
print(sum(fib(n)))
|