MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / mean

Function mean

maths/average_mean.py:4–22  ·  view source on GitHub ↗

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): ...

(nums: list)

Source from the content-addressed store, hash-verified

2
3
4def mean(nums: list) -> float:
5 """
6 Find mean of a list of numbers.
7 Wiki: https://en.wikipedia.org/wiki/Mean
8
9 >>> mean([3, 6, 9, 12, 15, 18, 21])
10 12.0
11 >>> mean([5, 10, 15, 20, 25, 30, 35])
12 20.0
13 >>> mean([1, 2, 3, 4, 5, 6, 7, 8])
14 4.5
15 >>> mean([])
16 Traceback (most recent call last):
17 ...
18 ValueError: List is empty
19 """
20 if not nums:
21 raise ValueError("List is empty")
22 return sum(nums) / len(nums)
23
24
25if __name__ == "__main__":

Callers 6

standardizationFunction · 0.85
round_robin.pyFile · 0.85
pi_estimatorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected