We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8727246 commit 16cd42cCopy full SHA for 16cd42c
Project Euler/Problem 02/sol2.py
@@ -1,13 +1,12 @@
1
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)
+ a, b, s = 0, 1, 0
+ while b < n:
+ if b % 2 == 0 and b < n: s += b
+ a, b = b, a+b
+ ls.append(s)
+
+T = int(input().strip())
+ls = []
+for _ in range(T):
+ fib(int(input().strip()))
+print(*ls, sep = '\n')
0 commit comments