In this problem, you will write a function that calculates the minimum, maximum, mean, and median values from a list of integers.
- Use the provided IPython notebook template stats.ipynb.
- Write a function named
get_stats()
takes one argument, which should be a list of integers, and returns a tuple(minimum, maximum, mean, median)
. The minimum and maximum values can be integers, but mean and median must be returned as floats.
When you are done writing the get_stats()
function, test your function by
running the following (provided in the template):
- Generate a list of numbers from 0 to 50 by using range() (and list()).
- Pass the above list to
get_stats()
as an argument. - Use the returned tuple to print out the minimum, maximum, mean, and median values in a nicely formatted manner. (If there is an even number of values in the list, there is no single middle value; in this case, take the median to be the mean of the two middle values.)
When you pass list(range(51))
(a list of integers from 0 to 50) to get_stats()
, your output should be
Minimum: 0
Maximum: 50
Mean: 25.0
Median: 25.0
See the template for more examples.
Your get_stats()
function should also be able to handle an unordered list
(Hint: use sorted()
in get_stats()
). Try passing a shuffled list, which you can generate by
>>> from random import shuffle
>>> my_list = [1, 2, 3, 4, 5]
>>> shuffle(my_list)
>>> print(my_list)
[3, 2, 1, 5, 4]
or try passing a list with repeated values, e.g.
my_list = [1, 1, 2, 2, 3, 4, 5]
Does your function behave as expected?