Skip to content

Commit 6deb893

Browse files
checks
1 parent 3b562a8 commit 6deb893

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

maths/series/arithmetic_mean.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def arithmetic_mean(series: list) -> float:
2727
4.0
2828
>>> arithmetic_mean([3, 6, 9, 12])
2929
7.5
30+
>>> arithmetic_mean(4)
31+
Traceback (most recent call last):
32+
...
33+
ValueError: Input series is not valid, valid series - [2, 4, 6]
3034
>>> arithmetic_mean([4, 8, 1])
3135
Traceback (most recent call last):
3236
...
@@ -39,13 +43,15 @@ def arithmetic_mean(series: list) -> float:
3943
ValueError: Input list must be a non empty list
4044
4145
"""
46+
if not isinstance(series, list):
47+
raise ValueError("Input series is not valid, valid series - [2, 4, 6]")
4248
if len(series) == 0:
4349
raise ValueError("Input list must be a non empty list")
4450
if not is_arithmetic_series(series):
4551
raise ValueError("Input list is not an arithmetic series")
4652
answer = 0
47-
for _ in series:
48-
answer += _
53+
for val in series:
54+
answer += val
4955
return answer / len(series)
5056

5157

0 commit comments

Comments
 (0)