diff --git a/squares.py b/squares.py index 893e1db..68642b6 100644 --- a/squares.py +++ b/squares.py @@ -1,8 +1,10 @@ -"""Computation of weighted average of squares.""" +from argparse import ArgumentParser + +"""Computation of weighted average of squares. This is on the new branch""" def average_of_squares(list_of_numbers, list_of_weights=None): - """ Return the weighted average of a list of values. + """ Return the weighted average of squares of a list of values. By default, all values are equally weighted, but this can be changed by the list_of_weights argument. @@ -29,7 +31,7 @@ def average_of_squares(list_of_numbers, list_of_weights=None): for number, weight in zip(list_of_numbers, effective_weights) ] - return sum(squares) + return sum(squares)/len(squares) def convert_numbers(list_of_strings): @@ -38,7 +40,7 @@ def convert_numbers(list_of_strings): Example: -------- >>> convert_numbers(["4", " 8 ", "15 16", " 23 42 "]) - [4, 8, 15, 16] + [4.0, 8.0, 15.0, 16.0, 23.0, 42.0] """ all_numbers = [] @@ -51,9 +53,22 @@ def convert_numbers(list_of_strings): if __name__ == "__main__": - numbers_strings = ["1","2","4"] - weight_strings = ["1","1","1"] + parser = ArgumentParser(description="Provide list of numbers to square and weight") + parser.add_argument('--numbers', '-n', nargs='+', help="Space separated list of numbers", default=["1","2","4"]) + parser.add_argument('--weights', '-w', nargs='+', help="Space separated ist of weights", default=["1","1","1"]) + # parser.add_argument('numbers', help="String of space separated numbers") + # parser.add_argument('weights', help="String of space separated weights") + arguments = parser.parse_args() + + # numbers_strings = ["1","2","4"] + numbers_strings = arguments.numbers + # weight_strings = ["1","1","1"] + weight_strings = arguments.weights + + # numbers_strings = numbers_strings.split() + # weight_strings = weight_strings.split() + numbers = convert_numbers(numbers_strings) weights = convert_numbers(weight_strings)