What you'll build
Import the statistics box and let it do the maths. Write one function that takes a list of scores and reports the average and the middle value — the five-line averaging loop, replaced by a function someone else already wrote.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- Start with
import statisticsat the top of the cell, before anything that uses it. - Define a function
summarise(scores)that usesstatistics.mean(scores)andstatistics.median(scores)to work out the average and the middle value. - Inside the function, use
round(mean, 1)so the average prints to one decimal place, andreturnboth numbers (or print them clearly). - Make a list of at least five scores, call the function on it, and print a short report — average and median, each labelled.
- Add the highest score to the report using the built-in
max(scores)— no import needed for that one. - Wrap the whole thing in a
forloop over two different lists of scores (e.g. two cohorts) and print a summary for each.
Examples
What your program should look like when it runs. Lines starting with $ are typed by you; the rest is your program.
Average score: 75.4
Middle score: 78Where to start
Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.
# Cohort score summary with statistics
import statistics
def summarise(scores):
# TODO: use statistics.mean and statistics.median
# TODO: round the average to 1 decimal place
# TODO: return (or print) the average and the median
pass
cohort = [78, 65, 92, 54, 88]
# TODO: call summarise(cohort) and print a labelled reportHow we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| It runs | Imports cleanly and prints the summary without errors. | 1 |
| Uses the library | The average and middle value come from `statistics.mean` and `statistics.median` with dot notation — not a hand-written loop. | 1 |
| Wrapped in a function | The work lives inside a `summarise(scores)` function that takes the list as a parameter, rather than loose code. | 1 |
| Reads well | The output is labelled, the average is rounded to one decimal place, and the numbers match the list given. | 1 |