
- Mean– mean is usually the average of all the elements(number) divided by the count of elements.
- Median– the median is the middle number among all the numbers divided by the count or frequency of the number. Like in 2, 3, 4, 5, 5, 6, 7, and 8, 5/2 will be the median.
- Mode– the mode is the middle number among all the numbers. Like in 2, 3, 4, 5, 5, 6, 7, and 8, 5 will be the mode.
#!/usr/bin/env python
def mean(arr, geometric= False):
if arr == []:
return None
if geometric:
prod = 1
for i in arr:
prod *= i
return round(prod**(1/len(arr)), 2)
else:
return sum(arr)/len(arr)
def median(arr):
if arr == []:
return None
arr.sort()
if len(arr)%2 != 0:
return arr[len(arr)//2]
else:
return (arr[len(arr)//2 - 1] + arr[len(arr)//2])/2
def mode(arr):
if arr == []:
return None
counts = {}
for i in set(arr):
count = arr.count(i)
counts[count] = i
return counts[max(counts.keys())]


