We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTdefmedian(x):x=sorted(x)length=len(x)iflength%2==0:half_length=(length// 2)median=(x[half_length-1]+x[half_length])/2else:half_length=length// 2median=x[half_length]returnmediandefmean(x):length=len(x)returnsum(x)/lengthdefmode(x):counter={}forvalinx:counter[val]=counter.get(val,0)+1max_frequency=max(counter.values())modes=[kfork,vincounter.items()ifv==max_frequency]# If multiple elements have the same max frequency, return the smallest onereturnint(min(modes))defstd(x):x_mean=mean(x)x_std=(sum(((val-x_mean)**2forvalinx))/len(x))**0.5returnx_stddefconfidence_interval(x):x_mean=mean(x)x_std=std(x)length=len(x)interval=1.96*(x_std/(length**0.5))lower,upper=x_mean-interval,x_mean+intervalreturnlower,upper,1if__name__=='__main__':length=input()values=[float(val)forvalininput().split(" ")]print(mean(values))print(median(values))print(mode(values))print(round(std(values),1))print(round(confidence_interval(values)[0],1),round(confidence_interval(values)[1],1))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Basic Statistics Warmup
You are viewing a single comment's thread. Return to all comments →
`Packages Used