Classy Tuesday is here! Today's problem is to create a function that takes in a list of integers and prints out the mean, median, and mode. For a bonus also print out the standard deviation.
Classy Tuesday is here! Today's problem is to create a function that takes in a list of integers and prints out the mean, median, and mode. For a bonus also print out the standard deviation.
Permalink: http://problemotd.com/problem/mean-median-mode/
Content curated by @MaxBurstein
Comments:
Johnathan - 11 years, 1 month ago
Here is my python solution
reply permalink
Max Burstein - 11 years, 1 month ago
Nice!
reply permalink
David - 11 years, 1 month ago
You can use ** for exponents.
You can replace duplicating a variable on the operation side with [operand]= [other variable]
You could also make your setup phase much more flexible by using a while loop instead of asking for the number of integers they want and asking in a for loop. As long as they give you an integer (or a float if you make a function for checking that) you ask for another.
Although it makes your code look more consistent, you can use a for loop on the list itself rather than on a range. This makes the most sense to point out for your use in mean() and sd() where you are not referencing more than one element per iteration.
becomes
Nice work
reply permalink
Johnathan - 11 years ago
Thanks for the feedback David.
reply permalink
Nick - 11 years ago
Bit late but here's my Java solution:
reply permalink