The Statistics Module

STEP 5: The statistics Module (Your Game’s Number Crunching Sidekick)

Alright young developer, welcome to the final boss of Unit 1.
You’ve survived math, randomness, timebending, and hacking your own computer (responsibly… I hope).
Now it’s time for Step 5, where Python helps you crunch numbers like a gamedev pro.

Every game needs stats. Damage stats.
Score stats.
Accuracy stats.
“How many times did the player miss the target even though it was RIGHT THERE?” stats.

Enter the statistics module — Python’s built in math nerd. It calculates averages, medians, and other fancy numbers so you don’t have to.

Think of it as the quiet kid in class who gets 100% on every test and never brags about it.
Let me guess… are you that kid, or are you the one asking to copy their homework?


1. Average Score (Mean)

import statistics

scores = [10, 20, 30, 40]
print("Average score:", statistics.mean(scores))
Try yourself.

Perfect for:

  • player score summaries
  • level difficulty balancing
  • proving your game is “totally fair” (even when it’s not)

2. Middle Value (Median)

import statistics

scores = [10, 20, 30, 40]
print("Median score:", statistics.median(scores))
Try yourself.

Useful when:

  • one player gets a ridiculous score and ruins the average
  • you want a “fair” middle number
  • you’re pretending to be a data scientist

Practice (Your Turn!)

Mini Challenge: Ultimate Stats Analyzer

Use the statistics module and Python’s built in functions to print:

  • Mean score
  • Median score
  • Mode score
  • Highest score
  • Lowest score

You’ll need:

statistics.mean(scores)
statistics.median(scores)
statistics.mode(scores)
max(scores)
min(scores)

If your list of scores looks like [10, 20, 20, 40] and the mode comes out as 20…
Congrats — that’s the number everyone apparently loves.

Modify and Run