2 6 9 8 5 2 4 6 8 1 8
Find mean, median, mode.
print("Enter list (separated by a space):")
a = input().split()
mean = 0
for i in range(len(a)):
a[i] = int(a[i])
mean += a[i]
mean = mean / len(a)
print(f"Mean: {mean:.2f}")
median = 0
a.sort()
print("Sort list:")
print(a)
if (len(a) % 2) == 0:
median = (a[(len(a)-1)//2] + a[((len(a)-1)//2)+1]) / 2
else:
median = a[((len(a)-1)//2) + 1]
print(f"Median: {median}")
mode = 0
mode_cnt = [0] * 10
for i in range(len(a)):
mode_cnt[a[i]] += 1
max_cnt = mode_cnt[0]
for i in range(len(mode_cnt)):
if max_cnt < mode_cnt[i]:
max_cnt = mode_cnt[i]
print("Mode:",end=" ")
for i in range(len(mode_cnt)):
if max_cnt == mode_cnt[i]:
print(f"{i}", end=" ")
Comments
Leave a comment