Flowchart for problem:
Detailed Python Code:
from collections import Counter
def mean(lst):
#n_num = [1, 2, 3, 4, 5]
if not lst:
return 0
n = len(lst)
get_sum = sum(lst)
mean = get_sum / n
return mean
def median(lst):
if not lst:
return 0
n = len(lst)
lst.sort()
if n % 2 == 0:
median1 = lst[n//2]
median2 = lst[n//2 - 1]
median = (median1 + median2)/2
else:
median = lst[n//2]
return median
def mode(lst):
if not lst:
return 0
counter = Counter(lst)
max_count = max(counter.values())
mode = [k for k,v in counter.items() if v == max_count]
return mode
if __name__ == '__main__':
lst = []
n = int(input("Enter number of elements : "))
#print("Enter "+n+" elements seperated by pressing enter")
for i in range(0, n):
ele = int(input())
lst.append(ele)
print(lst)
while True:
print("Press the number alongside to perform the required function:")
print("1.Mean")
print("2.Median")
print("3.Mode")
print("4.Exit")
n=int(input())
if(n==1):
print("mean of numbers: "+str(mean(lst)))
elif(n==2):
print("median of numbers: "+str(median(lst)))
elif(n==3):
print("mode of numbers: "+str(mode(lst)))
elif(n==4):
break
Get Answers For Free
Most questions answered within 1 hours.