diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b941d6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ + +*.ipynb \ No newline at end of file diff --git a/squares.py b/squares.py index d7e454e..b48b07f 100644 --- a/squares.py +++ b/squares.py @@ -12,7 +12,7 @@ def average_of_squares(list_of_numbers, list_of_weights=None): >>> average_of_squares([1, 2, 4]) 7.0 >>> average_of_squares([2, 4], [1, 0.5]) - 6.0 + 8.0 >>> average_of_squares([1, 2, 4], [1, 0.5]) Traceback (most recent call last): AssertionError: weights and numbers must have same length @@ -21,9 +21,9 @@ def average_of_squares(list_of_numbers, list_of_weights=None): if list_of_weights is not None: assert len(list_of_weights) == len(list_of_numbers), \ "weights and numbers must have same length" - effective_weights = list_of_weights + effective_weights = [val/sum(list_of_weights) for val in list_of_weights] else: - effective_weights = [1] * len(list_of_numbers) + effective_weights = [1/len(list_of_numbers)] * len(list_of_numbers) squares = [ weight * number * number for number, weight @@ -38,7 +38,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 = []