From 7af0c51dabfa37eb0856999f5b504819e917c89e Mon Sep 17 00:00:00 2001 From: Christopher Perez Date: Sat, 4 Mar 2023 15:31:07 -0500 Subject: [PATCH 1/3] changes --- Python/random_ints.py | 6 +++++- Python/square_root.py | 6 ++++-- Python/sum.py | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Python/random_ints.py b/Python/random_ints.py index 6ee968d..0449b59 100644 --- a/Python/random_ints.py +++ b/Python/random_ints.py @@ -1,7 +1,11 @@ import random def random_ints(): - # Your code here! + lst = [] + while True: + lst.append(random.randint(1,10)) + if lst[-1] == 6: + return lst def test(): diff --git a/Python/square_root.py b/Python/square_root.py index f3b7b33..66880ef 100644 --- a/Python/square_root.py +++ b/Python/square_root.py @@ -1,8 +1,10 @@ import math def square_root(n): - # Your code here! - return -1; + try: + return math.sqrt(n) + except: + return -1 def test(): assert square_root(4) == 2 diff --git a/Python/sum.py b/Python/sum.py index d1ae90e..686b8c3 100644 --- a/Python/sum.py +++ b/Python/sum.py @@ -1,6 +1,8 @@ def sum(lst, n): - # Your code here! - return False + count = 0 + for x in lst: + count += x + return count == n def test(): assert sum([-1, 1], 0) From d3969ee1f6727342785c20938f49d8f500ffb859 Mon Sep 17 00:00:00 2001 From: Christopher Perez Date: Sat, 4 Mar 2023 15:38:29 -0500 Subject: [PATCH 2/3] Update rm_smallest.py --- Python/rm_smallest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Python/rm_smallest.py b/Python/rm_smallest.py index de4885f..e54d348 100644 --- a/Python/rm_smallest.py +++ b/Python/rm_smallest.py @@ -1,6 +1,12 @@ def rm_smallest(d): - # Your code here! - return 0; + if not d: + return d + else: + min_value = min(d.values()) + min_key = [k for k, v in d.items() if v == min_value][0] + d.pop(min_key) + return d + def test(): assert 'a' in rm_smallest({'a':1,'b':-10}).keys() From cf7e1f25561df967a707d06f156c93d9bdbe5cf9 Mon Sep 17 00:00:00 2001 From: Christopher Perez Date: Mon, 6 Mar 2023 01:15:47 -0500 Subject: [PATCH 3/3] Update rm_smallest.py --- Python/rm_smallest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/rm_smallest.py b/Python/rm_smallest.py index e54d348..ab1414a 100644 --- a/Python/rm_smallest.py +++ b/Python/rm_smallest.py @@ -6,7 +6,7 @@ def rm_smallest(d): min_key = [k for k, v in d.items() if v == min_value][0] d.pop(min_key) return d - + def test(): assert 'a' in rm_smallest({'a':1,'b':-10}).keys()