Coding Python
Home›Python Coding Games›Module Market

Module Market — Modules & the standard library

Six jobs that are tedious by hand and trivial with the right import.

6 levels · Intermediate
Level 1

Checks
    Your PythonPython 3
    1

    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

    1. Off the maths shelf — math.sqrt, math.ceil, math.pi.
    2. Roll the dice — random.randint and random.sample.
    3. What day is it? — date, strftime and timedelta.
    4. Count them properly — collections.Counter, the short version of the loop you wrote in Dict Detective.
    5. Every combination — itertools.combinations and chain.
    6. Average it out — statistics.mean, median and pstdev.

    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

    ModuleReach for it when
    mathSquare roots, ceilings, trigonometry, constants
    randomShuffling, sampling, dice, picking a winner
    datetimeAny date arithmetic at all — never do it with plain numbers
    collectionsCounter, defaultdict, deque
    itertoolsCombinations, permutations, chaining, grouping
    statisticsMean, median, mode, standard deviation
    json / csvReading and writing structured files — see File Cabinet
    pathlibFile 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.

    Practise modules & the standard library on your phone — the Coding Python app runs real Python 3 on your phone, with examples, quizzes and challenges built in.
    Get it free

    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

    ← All Python coding games  Read the tutorial →

    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
    Coding Python app icon