← VCE Data Analytics U4O1

Descriptive statistics in Python with the statistics module

The statistics module calculates descriptive statistics on a list: mean() is the average, median() the middle value, stdev() the spread. Use import statistics first.

Understanding Descriptive statistics in Python with the statistics module in VCE Data Analytics U4O1

What it does: The statistics module must be imported first. Then statistics.mean() calculates the average of the list. stdev() calculates the sample standard deviation, which describes how spread out the values are around the mean. median() returns the middle value of the sorted list, which is 9. The mean is (2+4+9+11+20) / 5 = 9.2. Range is the highest value minus the lowest value. Adding them does not measure spread. The mean is the total divided by the number of values. sum() adds the values and len() counts them. len() counts the items in the list, so it returns 4. sum(data) is the function that returns the total, 45.

Common mistakes: The list is missing its closing square bracket. It should be data = [4, 8, 6, 5, 7]. print() needs a comma between its arguments. It should be print("Median:", mid).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 3–37) and word search (Modules 3–62).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line must come first before you can use statistics.mean() in Python?
import statisticsinclude statistics
Matches
print(mean(marks))
↓
mean() is called without the statistics prefix, so Python raises a NameError. Write statistics.mean(marks) after import statistics.
Applying
Meanings
Term
statistics.mean(data)
Meaning
The statistics module calculates descriptive statistics on a list: mean() is the average, median() the middle value, stdev() the spread. Use import statistics first.
Practice
import statistics
Testing
Gaps
statistics
Check Answer
Spots
1import statistics
2data = [4, 8, 6, 5, 7

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Desert Tortoise' badge — Desert Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line must come first before you can use statistics.mean() in Python?
A. import statistics ✓
B. include statistics
Python uses the import keyword to load a module. Without import statistics, calling statistics.mean() causes a NameError.
2. Which call finds the average of the list marks = [60, 70, 80]?
A. statistics.middle(marks)
B. statistics.mean(marks) ✓
mean() gives the average. The statistics module has no function called middle(). The middle value is found with median().
3. For data = [2, 4, 9, 11, 20], which function returns 9?
A. statistics.median(data) ✓
B. statistics.mean(data)
median() returns the middle value of the sorted list, which is 9. The mean is (2+4+9+11+20) / 5 = 9.2.
4. Which function measures the spread of the values in a list?
A. statistics.stdev(data) ✓
B. statistics.median(data)
stdev() gives the sample standard deviation, which shows how spread out the values are. median() gives the middle value, not the spread.
5. Which code finds the range of the list data?
A. max(data) + min(data)
B. max(data) - min(data) ✓
Range is the highest value minus the lowest value. Adding them does not measure spread.

Match the Pairs

statistics.median(marks) → Returns the middle value of the list marks once it is sorted
max(marks) - min(marks) → Calculates the range, the gap between the highest and lowest values
Make the statistics functions available before calculating the average of a list → import statistics print(statistics.mean(marks))
Measure the spread of a sample of data using standard deviation → statistics.stdev(marks)
print(mean(marks)) → mean() is called without the statistics prefix, so Python raises a NameError. Write statistics.mean(marks) after import statistics.
range = min(marks) - max(marks) → The subtraction is the wrong way round, which gives a negative range. It should be max(marks) - min(marks).

Key Term

statistics.mean(data)
The statistics module calculates descriptive statistics on a list: mean() is the average, median() the middle value, stdev() the spread. Use import statistics first.

Fill in the Blanks

1. import statistics marks = [72, 85, 90, 64] print(statistics.mean(marks))
Hint: Type the keyword that loads a module before you can use its functions.
2. import statistics marks = [72, 85, 90, 64] print(statistics.mean(marks))
Hint: Type the statistics function that calculates the average of the list.
3. import statistics ages = [15, 17, 16, 18, 16] print(statistics.median(ages))
Hint: Type the statistics function that finds the middle value of the sorted list.
4. import statistics scores = [4, 8, 6, 5, 7] print(statistics.stdev(scores))
Hint: Type the statistics function that measures how spread out the values are.
5. data = [12, 18, 9, 25, 14] spread = max(data) - min(data) print(spread)
Hint: Type the built-in function that returns the smallest value, so the range is the largest value minus this one.

Spot the Error

Question 1
A import statistics
B data = [4, 8, 6, 5, 7
C avg = statistics.mean(data)
D print(avg)
Line B — The list is missing its closing square bracket. It should be data = [4, 8, 6, 5, 7].
Question 2
A import statistics
B marks = [70, 85, 90, 65]
C mid = statistics.median(marks)
D print("Median:" mid)
Line D — print() needs a comma between its arguments. It should be print("Median:", mid).
Question 3
A import statistics
B marks = [52, 61, 75, 80, 68]
C sd = statistics.stdev(marks)
D print(round(s, 2))
Line D — The variable is called sd, not s, so Python would raise a NameError. It should be print(round(sd, 2)).
Question 4
A import statistics
B data = [3, 9, 4, 7, 12]
C total = sum[data]
D print(total / len(data))
Line C — Functions are called with round brackets, not square brackets. It should be total = sum(data).
Question 5
A data = [14, 22, 9, 31, 18]
B biggest = max(data)
C smallest = max(data)
D print(biggest - smallest)
Line C — The smallest value needs min(), not max(). With max() the range would always be 0. It should be smallest = min(data).

Student with a class code? Join your class →