Skip to content

Commit 16e95a3

Browse files
EthanVieirapoyea
authored andcommitted
p2 sol2 fixed (TheAlgorithms#669)
1 parent 8d4d950 commit 16e95a3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

project_euler/problem_02/sol2.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
def fib(n):
2-
a, b, s = 0, 1, 0
2+
"""
3+
Returns a list of all the even terms in the Fibonacci sequence that are less than n.
4+
"""
5+
ls = []
6+
a, b = 0, 1
37
while b < n:
4-
if b % 2 == 0 and b < n: s += b
8+
if b % 2 == 0:
9+
ls.append(b)
510
a, b = b, a+b
6-
ls.append(s)
11+
return ls
712

8-
T = int(input().strip())
9-
ls = []
10-
for _ in range(T):
11-
fib(int(input().strip()))
12-
print(ls, sep = '\n')
13+
if __name__ == '__main__':
14+
n = int(input("Enter max number: ").strip())
15+
print(sum(fib(n)))
File renamed without changes.

0 commit comments

Comments
 (0)