PY-18

Summarize a Sequence

  • Easy–Medium
  • Loops and Summaries
  • Python

Task

Write summarize_values(values). It receives a list of numbers and describes the whole sequence with one four-item tuple:

(count, minimum, maximum, mean)

For a non-empty list, the four positions mean:

  • count: the number of values;
  • minimum: the smallest value;
  • maximum: the largest value; and
  • mean: the arithmetic mean, found by adding all values and dividing by the count.

For an empty list, return None. Do not use Python's built-in statistics module. The input list must remain unchanged.

Example

The count is four, the extremes are 2 and 9, and the mean is (2 + 5 + 9 + 4) / 4, or 5.0. A one-value sequence has that value as both its minimum and maximum and the same value as its mean.

Your implementation

Edit solution.py and keep this function name and signature:

Return exactly None for an empty input. Otherwise return the four-item tuple in the stated order. mean should be the ordinary division result, including for fractional means. Do not print the result, ask for input, or mutate values.