p2 sol2 fixed (#669)

This commit is contained in:
Ethan Vieira 2019-02-09 10:59:43 -06:00 committed by John Law
parent 8d4d95099f
commit 16e95a3de5
2 changed files with 11 additions and 8 deletions

View File

@ -1,12 +1,15 @@
def fib(n): def fib(n):
a, b, s = 0, 1, 0 """
while b < n: Returns a list of all the even terms in the Fibonacci sequence that are less than n.
if b % 2 == 0 and b < n: s += b """
a, b = b, a+b
ls.append(s)
T = int(input().strip())
ls = [] ls = []
for _ in range(T): a, b = 0, 1
fib(int(input().strip())) while b < n:
print(ls, sep = '\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)))