mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-27 08:56:44 +00:00
checks
This commit is contained in:
parent
3b562a8507
commit
6deb893d4f
@ -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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user