AssignmentsWeek 03 · Data and the outside worldCohort score summary with statistics
wk03.p4Practice exerciseWeek 03 · Data and the outside worldOpen · due this week

Cohort score summary with statistics

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.

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.

  1. Start with import statistics at the top of the cell, before anything that uses it.
  2. Define a function summarise(scores) that uses statistics.mean(scores) and statistics.median(scores) to work out the average and the middle value.
  3. Inside the function, use round(mean, 1) so the average prints to one decimal place, and return both numbers (or print them clearly).
  4. Make a list of at least five scores, call the function on it, and print a short report — average and median, each labelled.
Bonus, if you're feeling brave
  • 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 for loop 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.

Example cell runs
Average score: 75.4
Middle score: 78

Where 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 report

How we'll grade it

Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.

CheckWhat we look forPt
It runsImports cleanly and prints the summary without errors.1
Uses the libraryThe average and middle value come from `statistics.mean` and `statistics.median` with dot notation — not a hand-written loop.1
Wrapped in a functionThe work lives inside a `summarise(scores)` function that takes the list as a parameter, rather than loose code.1
Reads wellThe output is labelled, the average is rounded to one decimal place, and the numbers match the list given.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →