Skip to content

Commit

Permalink
Add functionality in order to get numbers and weights from files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaos Schoinas committed Nov 26, 2020
1 parent caca12c commit 34eb15c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions week06/average-squares-example/average_squares/squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ def convert_numbers(list_of_strings):
if __name__ == "__main__":

parser = ArgumentParser(description="Weighted mean of squared numbers")
parser.add_argument("numbers", nargs='+', help="the list of numbers")
parser.add_argument("--weights", "-w", nargs='+', help="the list of weights")
parser.add_argument("numbers", help="the lifile containing the numbers")
parser.add_argument("--weights", "-w", help="the optional file containing the weights")
arguments = parser.parse_args()

numbers = convert_numbers(arguments.numbers)
with open(arguments.numbers) as file:
numbers = [int(x) for x in next(file).split()]

if arguments.weights:
weights = convert_numbers(arguments.weights)
with open(arguments.weights) as file:
weights = [int(x) for x in next(file).split()]
else:
weights = [1] * len(numbers)

Expand Down

1 comment on commit 34eb15c

@nikoSchoinas
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.