forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaverage_mean.py
More file actions
Latest commit
28 lines (22 loc) · 574 Bytes
/
Copy pathaverage_mean.py
File metadata and controls
28 lines (22 loc) · 574 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from __future__ importannotations
defmean(nums: list) ->float:
"""
Find mean of a list of numbers.
Wiki: https://en.wikipedia.org/wiki/Mean
>>> mean([3, 6, 9, 12, 15, 18, 21])
12.0
>>> mean([5, 10, 15, 20, 25, 30, 35])
20.0
>>> mean([1, 2, 3, 4, 5, 6, 7, 8])
4.5
>>> mean([])
Traceback (most recent call last):
...
ValueError: List is empty
"""
ifnotnums:
raiseValueError("List is empty")
returnsum(nums) /len(nums)
if__name__=="__main__":
importdoctest
doctest.testmod()