From 7f6fba9f99e478699b3e8f4da2759eac00f5e67f Mon Sep 17 00:00:00 2001 From: nikki2906 <104235980+nikki2906@users.noreply.github.com> Date: Fri, 7 Apr 2023 00:09:36 -0400 Subject: [PATCH 1/4] Initial Update. --- Python/random_ints.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Python/random_ints.py b/Python/random_ints.py index 6ee968d..60a5de0 100644 --- a/Python/random_ints.py +++ b/Python/random_ints.py @@ -1,8 +1,17 @@ import random def random_ints(): - # Your code here! - +# initialize an empty list to store the numbers + numbers = [] + # initialize a variable to store the current number + number = 0 + # loop until the number is 6 + while number != 6: + # generate a random number in the range [1,10] + number = int(random.random()*10) + 1 + # append the number to the list + numbers.append(number) + return numbers def test(): N = 10000 From 4405f5fd9fa222fe0b2452192c2096b38a64e957 Mon Sep 17 00:00:00 2001 From: nikki2906 <104235980+nikki2906@users.noreply.github.com> Date: Fri, 7 Apr 2023 00:10:05 -0400 Subject: [PATCH 2/4] Initial Update. --- Python/rm_smallest.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Python/rm_smallest.py b/Python/rm_smallest.py index de4885f..d7d095e 100644 --- a/Python/rm_smallest.py +++ b/Python/rm_smallest.py @@ -1,12 +1,27 @@ +# take in argument d def rm_smallest(d): - # Your code here! - return 0; + # if the dictionary is empty, return the original dictionary + if not d: + return d + + # find the minimum value in the dictionary + min_value = min(d.values()) + + # find the key(s) that correspond to the minimum value + min_keys = [k for k, v in d.items() if v == min_value] + + # remove the key-value pair(s) from the dictionary + for k in min_keys: + d.pop(k) + + # return the modified dictionary + return d def test(): assert 'a' in rm_smallest({'a':1,'b':-10}).keys() assert not 'b' in rm_smallest({'a':1,'b':-10}).keys() assert not 'a' in rm_smallest({'a':1,'b':5,'c':3}).keys() - rm_smallest({}) + assert rm_smallest({}) == {} print("Success!") if __name__ == "__main__": From 6e5eeed282e89f8c19845b757031fa6a7b32231f Mon Sep 17 00:00:00 2001 From: nikki2906 <104235980+nikki2906@users.noreply.github.com> Date: Fri, 7 Apr 2023 00:11:09 -0400 Subject: [PATCH 3/4] Initial Update. --- Python/square_root.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Python/square_root.py b/Python/square_root.py index f3b7b33..29f2a92 100644 --- a/Python/square_root.py +++ b/Python/square_root.py @@ -1,8 +1,11 @@ import math - +# takes a single argument, n. def square_root(n): - # Your code here! - return -1; + if isinstance(n, (int, float)): + if n >= 0: + return math.sqrt(n) + return -1 + def test(): assert square_root(4) == 2 From 05e15c842ae139349d4ee04d81cb8abb436168a3 Mon Sep 17 00:00:00 2001 From: nikki2906 <104235980+nikki2906@users.noreply.github.com> Date: Fri, 7 Apr 2023 00:11:32 -0400 Subject: [PATCH 4/4] Initial Update. --- Python/sum.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Python/sum.py b/Python/sum.py index d1ae90e..e59c244 100644 --- a/Python/sum.py +++ b/Python/sum.py @@ -1,6 +1,13 @@ def sum(lst, n): - # Your code here! - return False + # initialize the sum to zero + total = 0 + + # loop over the list and add each element to the total + for num in lst: + total += num + + # check if the sum equals the given number n and return the appropriate boolean value + return total == n def test(): assert sum([-1, 1], 0)