Skip to content

Commit 16cd42c

Browse files
authored
Updated sol2.py to make it work as expected
1 parent 8727246 commit 16cd42c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Project Euler/Problem 02/sol2.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
def fib(n):
2-
ls = []
3-
a,b = 0,1
4-
n += 1
5-
for i in range(n):
6-
if (b % 2 == 0):
7-
ls.append(b)
8-
else:
9-
pass
10-
a,b = b, a+b
11-
print (sum(ls))
12-
return None
13-
fib(10)
2+
a, b, s = 0, 1, 0
3+
while b < n:
4+
if b % 2 == 0 and b < n: s += b
5+
a, b = b, a+b
6+
ls.append(s)
7+
8+
T = int(input().strip())
9+
ls = []
10+
for _ in range(T):
11+
fib(int(input().strip()))
12+
print(*ls, sep = '\n')

0 commit comments

Comments
 (0)