From 16e95a3de5f81bbc0ce9d8a96f42e1a67aa7187c Mon Sep 17 00:00:00 2001 From: Ethan Vieira Date: Sat, 9 Feb 2019 10:59:43 -0600 Subject: [PATCH] p2 sol2 fixed (#669) --- project_euler/problem_02/sol2.py | 19 +++++++++++-------- .../{Problem 31 => problem_31}/sol1.py | 0 2 files changed, 11 insertions(+), 8 deletions(-) rename project_euler/{Problem 31 => problem_31}/sol1.py (100%) diff --git a/project_euler/problem_02/sol2.py b/project_euler/problem_02/sol2.py index aa8dc7f76..a2772697b 100644 --- a/project_euler/problem_02/sol2.py +++ b/project_euler/problem_02/sol2.py @@ -1,12 +1,15 @@ def fib(n): - a, b, s = 0, 1, 0 + """ + 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 and b < n: s += b + if b % 2 == 0: + ls.append(b) a, b = b, a+b - ls.append(s) + return ls -T = int(input().strip()) -ls = [] -for _ in range(T): - fib(int(input().strip())) -print(ls, sep = '\n') +if __name__ == '__main__': + n = int(input("Enter max number: ").strip()) + print(sum(fib(n))) diff --git a/project_euler/Problem 31/sol1.py b/project_euler/problem_31/sol1.py similarity index 100% rename from project_euler/Problem 31/sol1.py rename to project_euler/problem_31/sol1.py