Module Market — Modules & the standard library
Six jobs that are tedious by hand and trivial with the right import.
How to play
Each level is a task that you could write yourself in twenty lines, and that the standard library already does in one. The skill being practised is not syntax — it is knowing what is on the shelf. Import the right module, press Run, and the values you produced are shown with their types.
What each level teaches
- Off the maths shelf —
math.sqrt,math.ceil,math.pi. - Roll the dice —
random.randintandrandom.sample. - What day is it? —
date,strftimeandtimedelta. - Count them properly —
collections.Counter, the short version of the loop you wrote in Dict Detective. - Every combination —
itertools.combinationsandchain. - Average it out —
statistics.mean,medianandpstdev.
Why level 2 does not check your numbers
It checks the rules instead: that the roll is between 1 and 6, that the hand has three different cards, and that they all came from the deck. Testing random code by pinning the exact output is fragile — it breaks when the seed, the Python version or the call order changes. Testing the properties that must always hold is how you test randomness properly, and it is a habit worth taking with you.
The modules worth knowing by name
| Module | Reach for it when |
|---|---|
math | Square roots, ceilings, trigonometry, constants |
random | Shuffling, sampling, dice, picking a winner |
datetime | Any date arithmetic at all — never do it with plain numbers |
collections | Counter, defaultdict, deque |
itertools | Combinations, permutations, chaining, grouping |
statistics | Mean, median, mode, standard deviation |
json / csv | Reading and writing structured files — see File Cabinet |
pathlib | File paths, instead of gluing strings together |
Mean or median?
Level 6 uses [5, 7, 6, 8, 99] deliberately. The mean is 25 — a number that describes
none of the data — while the median is 7, which describes almost all of it. One outlier drags the mean
and leaves the median alone. Knowing which to use is worth more than knowing how to call either. The written tour
is in the modules and standard library tutorial.
Frequently asked questions
What is the Python standard library?
The set of modules that ship with Python itself — math, random, datetime, json, csv, collections, itertools and many more. No installation needed; just import them.
What is the difference between import math and from math import sqrt?
import math brings in the module, so you write math.sqrt(). from math import sqrt brings in that one name, so you write sqrt(). The first makes the origin obvious, which matters in a long file.
How do I pick random items without repeats?
random.sample(population, k) draws k different items. Calling random.choice several times can return the same item more than once.
How do I add days to a date in Python?
Use timedelta: date(2026, 1, 15) + timedelta(days=30). Never add plain numbers to a date — timedelta handles month lengths and leap years for you.
Should I use mean or median?
Use the median when outliers would distort the picture, as with salaries or house prices. Use the mean when every value should pull its weight. Level 6 shows a set where they differ by 18.
Keep going
- Read the modules & the standard library tutorial — the written explanation behind every level here.
- Variable Vault — variables & data types.
- Operator Arcade — numbers & operators.
- String Surgeon — strings & slicing.
- 20 Python practice exercises with worked solutions.
Take the games with you
Coding Python packs a real Python 3 compiler, 30 example programs, 112 quiz questions and 12 self-checking challenges into one free Android app.
Get it on Google Play