Hackerrank Day 0: Mean, Median, and Mode

 

Output Format

Print  lines of output in the following order:

  1. Print the mean on a new line, to a scale of  decimal place (i.e., , ).
  2. Print the median on a new line, to a scale of  decimal place (i.e., , ).
  3. Print the mode on a new line; if more than one such value exists, print the numerically smallest one.

Sample Input

10
64630 11735 14216 99233 14470 4978 73429 38120 51135 67060

Sample Output

43900.6
44627.5
4978
size=int(input())
data=list(map(int,str(input()).split(' ')))
meanvalue=sum(data)/size
print(round(meanvalue,1))

data=sorted(data)#######
if size%2==0:
    median=(data[size//2]+data[size//2-1])/2
else:
    median=data[size//2]
print(round(median,1))

maxcount=0
for ele in data:
    count=data.count(ele)#######
    if count>maxcount:
        maxcount=count
        mode=ele
print(mode)

 

Published 128 original articles · won praise 90 · views 4863

Guess you like

Origin blog.csdn.net/weixin_45405128/article/details/103936793