Last active
September 5, 2016 11:27
-
-
Save ooade/d8d3a0950d7268c3c93a7c30ad7c1c47 to your computer and use it in GitHub Desktop.
Hackerrank 10 Days of statistics, Day 0: Mean, Median, and Mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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