From e24b729deca4a15e18a788b5594127b5fe6f64b4 Mon Sep 17 00:00:00 2001 From: Sophie Morrison Date: Thu, 23 Nov 2023 10:31:23 +0000 Subject: [PATCH 1/3] added numbers arg --- squares.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/squares.py b/squares.py index d7e454e..bf3e539 100644 --- a/squares.py +++ b/squares.py @@ -1,3 +1,4 @@ +from argparse import ArgumentParser """Computation of weighted average of squares.""" @@ -51,10 +52,14 @@ def convert_numbers(list_of_strings): if __name__ == "__main__": - numbers_strings = ["1","2","4"] - weight_strings = ["1","1","1"] + #numbers_strings = ["1","2","4"] + weight_strings = ["1","1","1"] + parser = ArgumentParser(description="Compute weighted average of squares") + parser.add_argument('numbers', nargs='+') + #parser.add_argument('--weights', '-w', action="store_true") + arguments= parser.parse_args() - numbers = convert_numbers(numbers_strings) + numbers = convert_numbers(arguments.numbers) weights = convert_numbers(weight_strings) result = average_of_squares(numbers, weights) From aa0ed19bd8a1abd065d0311792bf4cfe7a6120bb Mon Sep 17 00:00:00 2001 From: Sophie Morrison Date: Thu, 23 Nov 2023 10:42:49 +0000 Subject: [PATCH 2/3] added optional weights --- squares.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/squares.py b/squares.py index bf3e539..f47e53c 100644 --- a/squares.py +++ b/squares.py @@ -53,14 +53,14 @@ def convert_numbers(list_of_strings): if __name__ == "__main__": #numbers_strings = ["1","2","4"] - weight_strings = ["1","1","1"] + #weight_strings = ["1","1","1"] parser = ArgumentParser(description="Compute weighted average of squares") parser.add_argument('numbers', nargs='+') - #parser.add_argument('--weights', '-w', action="store_true") + parser.add_argument('--weights', '-w', nargs='+') arguments= parser.parse_args() numbers = convert_numbers(arguments.numbers) - weights = convert_numbers(weight_strings) + weights = convert_numbers(arguments.weights) result = average_of_squares(numbers, weights) From 33ab34cf0a4c46239743c3af6ed37adfe8541ee5 Mon Sep 17 00:00:00 2001 From: Sophie Morrison Date: Thu, 23 Nov 2023 10:51:10 +0000 Subject: [PATCH 3/3] added types and help --- squares.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/squares.py b/squares.py index f47e53c..054cff1 100644 --- a/squares.py +++ b/squares.py @@ -55,8 +55,8 @@ def convert_numbers(list_of_strings): #numbers_strings = ["1","2","4"] #weight_strings = ["1","1","1"] parser = ArgumentParser(description="Compute weighted average of squares") - parser.add_argument('numbers', nargs='+') - parser.add_argument('--weights', '-w', nargs='+') + parser.add_argument('numbers', nargs='+', type=float, help='List of numbers to average') + parser.add_argument('--weights', '-w', nargs='+', type=float, help='Weight to apply') arguments= parser.parse_args() numbers = convert_numbers(arguments.numbers)