diff --git a/maths/series/arithmetic_mean.py b/maths/series/arithmetic_mean.py index 994f479d1..2519a8a35 100644 --- a/maths/series/arithmetic_mean.py +++ b/maths/series/arithmetic_mean.py @@ -27,6 +27,10 @@ def arithmetic_mean(series: list) -> float: 4.0 >>> arithmetic_mean([3, 6, 9, 12]) 7.5 + >>> arithmetic_mean(4) + Traceback (most recent call last): + ... + ValueError: Input series is not valid, valid series - [2, 4, 6] >>> arithmetic_mean([4, 8, 1]) Traceback (most recent call last): ... @@ -39,13 +43,15 @@ def arithmetic_mean(series: list) -> float: ValueError: Input list must be a non empty list """ + if not isinstance(series, list): + raise ValueError("Input series is not valid, valid series - [2, 4, 6]") if len(series) == 0: raise ValueError("Input list must be a non empty list") if not is_arithmetic_series(series): raise ValueError("Input list is not an arithmetic series") answer = 0 - for _ in series: - answer += _ + for val in series: + answer += val return answer / len(series)