A teacher's spreadsheet shows one summary line under every column of marks. Write summary(values) that returns a dictionary with these keys:
"n": the number of values;"mean"and"median";"modes": all the most common values, in increasing order;"stdev": the sample standard deviation (dividing byn - 1), orNonewhen there are fewer than two values;"quartiles": the three cut points that divide the data into four equal groups, computed exactly asstatistics.quantiles(values, n=4)does with its default method, orNonewhen there are fewer than two values.
For an empty list, raise statistics.StatisticsError, the error the statistics module itself uses for this case. The helper exam_marks(n, seed) generates marks, and raises(fn, *args) returns the name of the exception raised (or None).
Examples
Input: summary([2, 4, 4, 5, 7, 9])
Output: {"n": 6, "mean": 5.1666..., "median": 4.5, "modes": [4], "stdev": 2.4832...,
"quartiles": [3.5, 4.5, 7.5]}
Input: summary([10])
Output: {"n": 1, "mean": 10, "median": 10, "modes": [10], "stdev": None, "quartiles": None}
Input: raises(summary, [])
Output: "StatisticsError"
Constraints
0 <= len(values) <= 10**5; values are integers or floats.- Numbers are compared with a tolerance of
1e-6.
Goals
- Import a standard-library module instead of rewriting what it already provides
- Look up which function of `statistics` answers each question
- Let the library's own exception report an empty dataset