return the arithmetic mean of series >>> arithmetic_mean([2, 4, 6]) 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_me
(series: list)
| 40 | |
| 41 | |
| 42 | def arithmetic_mean(series: list) -> float: |
| 43 | """ |
| 44 | return the arithmetic mean of series |
| 45 | |
| 46 | >>> arithmetic_mean([2, 4, 6]) |
| 47 | 4.0 |
| 48 | >>> arithmetic_mean([3, 6, 9, 12]) |
| 49 | 7.5 |
| 50 | >>> arithmetic_mean(4) |
| 51 | Traceback (most recent call last): |
| 52 | ... |
| 53 | ValueError: Input series is not valid, valid series - [2, 4, 6] |
| 54 | >>> arithmetic_mean([4, 8, 1]) |
| 55 | 4.333333333333333 |
| 56 | >>> arithmetic_mean([1, 2, 3]) |
| 57 | 2.0 |
| 58 | >>> arithmetic_mean([]) |
| 59 | Traceback (most recent call last): |
| 60 | ... |
| 61 | ValueError: Input list must be a non empty list |
| 62 | |
| 63 | """ |
| 64 | if not isinstance(series, list): |
| 65 | raise ValueError("Input series is not valid, valid series - [2, 4, 6]") |
| 66 | if len(series) == 0: |
| 67 | raise ValueError("Input list must be a non empty list") |
| 68 | answer = 0 |
| 69 | for val in series: |
| 70 | answer += val |
| 71 | return answer / len(series) |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected