-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculated_mean_median_mode.py
More file actions
39 lines (28 loc) · 1018 Bytes
/
calculated_mean_median_mode.py
File metadata and controls
39 lines (28 loc) · 1018 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
29
30
31
32
33
34
35
36
37
38
39
#def add (a,b):
#return a+b
#print(add(5,4))
#def capitalize(f_name,s_name):
#name_person=f_name.capitalize(),s_name.title()
#return name_person
#print(capitalize("avinash","jenny"))
#def area_of_rectangle():
# l=int(input("enter a lenght: "))
# wid=int(input("enter a width: "))
# area = wid*l
# return f"area of rectangl:{area}"
#print(area_of_rectangle())
from collections import Counter
def mean_med_mode(list1):
mean = sum(list1) / len(list1)
sorted_value=sorted(list1)
n=len(sorted_value)
if n%2==0:
med=(sorted_value[(n // 2)-1] +sorted_value[n // 2]) /2
else:
med=sorted_value[n // 2]
data=Counter(list1)
mode_da=data.most_common()
max_count=mode_da[0][1]
mode=[val for val,count in mode_da if count== max_count]
return mean, med, mode
print(f"Mean: {mean_med_mode([1, 2, 2, 3, 4, 4, 4, 5])[0]}, Median: {mean_med_mode([1, 2, 2, 3, 4, 4, 4, 5])[1]}, Mode: {mean_med_mode([1, 2, 2, 3, 4, 4, 4, 5])[2]}")