Skip to content

Instantly share code, notes, and snippets.

@ooade
Last active September 5, 2016 11:27
Show Gist options
  • Select an option

  • Save ooade/d8d3a0950d7268c3c93a7c30ad7c1c47 to your computer and use it in GitHub Desktop.

Select an option

Save ooade/d8d3a0950d7268c3c93a7c30ad7c1c47 to your computer and use it in GitHub Desktop.
Hackerrank 10 Days of statistics, Day 0: Mean, Median, and Mode
from scipy.stats import mode
raw_input();
ARR = raw_input();
def median(nums):
nums = sorted(nums)
if len(nums) % 2 == 0:
# if even, grab the two mid letters
return (nums[int(len(nums) / 2) - 1] + nums[int(len(nums) / 2)]) / 2.0
else:
return nums[int(len(nums) / 2)]
def mean(nums):
return sum(nums) / float(len(nums))
ARR = [int(i) for i in ARR.split()] #splits the Array and make each value an interger
print mean(ARR)
print median(ARR)
print mode(ARR)[0][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment