mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 21:41:08 +00:00
16 lines
361 B
Python
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)))
|