You are viewing a single comment's thread. Return to all comments →
''' from statistics import mean, median, mode
n = input() x = sorted(list(map(int, input().split(" "))))
print(mean(x)) print(median(x)) print(mode(x)) ''' from collections import Counter
def mean(i): output = sum(i)/len(i) return output
def median(i): i.sort() mid = len(i) // 2
if len(i) % 2 == 0: med = (i[mid] + i[mid - 1]) / 2 else: med = i[mid] return med
def mode(i): count = Counter(i) max_count = max(count.values()) modes = [key for key, count in count.items() if count == max_count] return min(modes) if len(modes) > 1 else modes[0]
print(mean(x)) print(median(x)) print(mode(x))
Seems like cookies are disabled on this browser, please enable them to open this website
Day 0: Mean, Median, and Mode
You are viewing a single comment's thread. Return to all comments →
Enter your code here. Read input from STDIN. Print output to STDOUT
''' from statistics import mean, median, mode
n = input() x = sorted(list(map(int, input().split(" "))))
print(mean(x)) print(median(x)) print(mode(x)) ''' from collections import Counter
n = input() x = sorted(list(map(int, input().split(" "))))
def mean(i): output = sum(i)/len(i) return output
def median(i): i.sort() mid = len(i) // 2
def mode(i): count = Counter(i) max_count = max(count.values()) modes = [key for key, count in count.items() if count == max_count] return min(modes) if len(modes) > 1 else modes[0]
print(mean(x)) print(median(x)) print(mode(x))