Python Arena
Step 3 of 3

Finding the right module

Before you write a function, it's worth checking whether the standard library already has one. Its modules are listed by theme in Python's documentation, at docs.python.org/3/library: text, numbers and mathematics, dates, files, data formats such as CSV and JSON, and much more. Beyond the standard library, thousands of modules written by other programmers are at the Python Package Index, pypi.org, and on your own computer you install them with a tool called pip. This site runs only the standard library.

Here are two finds that save real work.

statistics

The statistics module calculates averages and more. mean is the ordinary average, and median the middle value when the values are in order:

import statistics

lap_times = [12.5, 11.8, 13.1, 12.0, 30.2]
print(statistics.mean(lap_times))
print(statistics.median(lap_times))
Output
15.92
12.5

One lap went badly (30.2 seconds), and it pulls the mean up. The median stays a typical lap time, which is why the median is often the better summary of data with outliers. With an even number of values, the median is the mean of the two middle ones.

difflib

The difflib module compares texts. Its function get_close_matches(word, possibilities) returns the strings of the list that look most like the word, the most similar first, and an empty list when nothing is close. Python's own "Did you mean" messages work in a similar way:

from difflib import get_close_matches

commands = ["help", "start", "stop", "status", "quit"]
print(get_close_matches("hlep", commands))
print(get_close_matches("strat", commands))
print(get_close_matches("xyz", commands))
Output
['help']
['start', 'status']
[]

Reading a documentation entry

The documentation shows a function by its first line, followed by a description. The entry for this one starts with difflib.get_close_matches(word, possibilities, n=3, cutoff=0.6). The parameters with = have a default value: you can leave them out, and then the function returns at most 3 matches (n) and only fairly close ones (cutoff). Most entries work like this, so knowing how to read one lets you use functions you have never seen before.

Your task

Challenge 1 of 3

Fill in the blank so the program prints the middle value of the ages (27), not their average.

Challenge 2

Write a command prompt that helps with typos. It asks for commands until the command is quit, and then prints Bye!. A known command (one of the list commands in the starter code) is answered with Running and its name. An unknown one is answered with a suggestion from get_close_matches, its first match, or without one if there's no match. For example:

Command: strat
Unknown command strat. Did you mean start?
Command: start
Running start
Command: xyz
Unknown command xyz.
Command: quit
Bye!

Challenge 3

The file temperatures.csv has a date and a temperature (a float) on each line, separated by a comma. Write a program that reads it with the csv module and prints the mean and the median of the temperatures with one decimal, using the statistics module. For example, for this file:

2026-03-01,4.5
2026-03-02,6.0
2026-03-03,5.5
2026-03-04,12.0

the program prints:

Mean: 7.0
Median: 5.8