Lesson 1 of 18

Mean, Median, Mode

Central Tendency

The three most important measures of central tendency:

  • Mean — the arithmetic average: ar{x} = rac{1}{n}sum_{i=1}^n x_i
  • Median — the middle value when data is sorted
  • Mode — the most frequently occurring value
import statistics

data = [2, 4, 4, 4, 5, 5, 7, 9]

print(round(statistics.fmean(data), 1))   # 5.0
print(round(statistics.median(data), 1))  # 4.5
print(statistics.mode(data))              # 4

When to Use Each

MeasureBest forSensitive to outliers?
MeanSymmetric distributionsYes
MedianSkewed data, outliers presentNo
ModeCategorical data, most commonNo

Your Task

Implement central_tendency(data) that prints the mean (rounded to 1 decimal), median (rounded to 1 decimal), and mode of the input list.

Pyodide loading...
Loading...
Click "Run" to execute your code.