You are viewing a single comment's thread. Return to all comments →
This is my algoritmic solution in python. I just use math library to round floor for counting the median:
import math` n = int(input()) x = input().split(" ") for i in range(len(x)): x[i] = int(x[i]) x.sort() print(sum(x)/n) if(n%2==0): print((x[int(n/2)-1]+x[int(n/2)])/2) else: print(x[math.floor(n/2)]) occur = 0 high = 0 modus = x[0] for i in range(1, n): if (x[i] == x[i-1]): occur += 1 if occur > high: modus = x[i] high = occur else: occur = 0 print(modus) `
import math`
n = int(input())
x = input().split(" ")
for i in range(len(x)): x[i] = int(x[i])
x.sort()
print(sum(x)/n)
if(n%2==0): print((x[int(n/2)-1]+x[int(n/2)])/2) else: print(x[math.floor(n/2)])
occur = 0 high = 0 modus = x[0] for i in range(1, n): if (x[i] == x[i-1]): occur += 1 if occur > high: modus = x[i] high = occur else: occur = 0
print(modus)
`
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 →
This is my algoritmic solution in python. I just use math library to round floor for counting the median: