My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
HackerRank

Photo by Kevin Bhagat on Unsplash

HackerRank

PracticeTutorials10 Days of Statistics

Ashok Acharya's photo
Ashok Acharya
·Mar 14, 2015·

1 min read

Day 0: Mean, Median, and Mode

# Enter your code here. Read input from STDIN. Print output to STDOUT
n=int(input())
x=input()
x=x.split(" ")

X=[]
for i in x:
    X.append(int(i))
print(sum(X)/n)
X.sort()

print((X[int(((n-1)/2))]+X[(int(n/2))])/2)

temp =X
mode=[]
for i in temp:
    mode.append(temp.count(i))

if max(mode)==1:
    print(X[0])
else:
    print(X[max(mode).index])