CoursePython from Scratch to Intermediate · Module 6: Functions · part 43 of 75
Part 43 · Module 6: Functions

Lab: Five shelf functions, each checked with assert

11 min read·14 Oct 2026
Module 6 · Lab · About 50 minutes · Needs: lessons 1 to 3 of this module, and Module 5 (lists, dictionaries, comprehensions)

What you are building

borrow day and today due_date day + 14 is_overdue True or False days_late 0 or more late_fee pence, capped reminder_text the message assert checks: 580p owed
The five settled functions (blue) and how each uses the one before it; assert checks (green) prove they give the course's 580p for 14 October.

Amira's question for this module is "I want the same answer every time." The three lessons built the shelf's rules as functions, but each lesson wrote them a little differently. This lab settles them: one final version of each of the five functions the rest of the course uses, due_date, is_overdue, days_late, late_fee and reminder_text, each proved with assert against answers you already know.

Then you run all twelve loans of the course's slice through them. The four overdue loans must owe 580 pence, the same figure every module reaches. In Module 7 these five functions move, unchanged in meaning, into the booknook package.

Open a new Colab notebook, call it module-06-lab.ipynb, and run each cell in order.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.