From 6deb893d4ff813627fb9ab4decf2df572c9728dc Mon Sep 17 00:00:00 2001 From: ayushbisht2001 <61404154+ayushbisht2001@users.noreply.github.com> Date: Mon, 1 Mar 2021 21:53:15 +0530 Subject: [PATCH] checks --- maths/series/arithmetic_mean.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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)