Editor

Mean, Median and Mode

#545 · Modules and random · Beginner · 30 XP · about 5 min

The statistics module describes data in a few words. Write mark_summary(marks) that returns a tuple (mean, median, mode) for a list of whole-number marks:

  • mean: the total divided by how many marks there are, as a float rounded to one decimal place.
  • median: the middle mark once they are sorted, or the average of the two middle marks when there is an even number of them.
  • mode: the mark that appears most often. If several marks are equally common, the one that appears first in marks.

statistics.mean, statistics.median and statistics.mode follow these rules.

Examples

mark_summary([70, 85, 85, 90, 60])  # returns (78.0, 85, 85)
mark_summary([50, 60, 70, 80])      # returns (65.0, 65.0, 50)

In the second example no mark repeats, so every mark is equally common and the first one, 50, is the mode. The two middle marks are 60 and 70, so the median is 65.0.

Constraints

  • marks holds at least one mark, and at most 10,000.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.