CoursePython from Scratch to Intermediate · Module 2: Values, Types and Operators · part 18 of 75
Part 18 · Module 2: Values, Types and Operators

Lab: The late-fee calculator for six loans

11 min read·14 Oct 2026
Module 2 · Lab · About 45 minutes · Needs: lessons 1 to 4 of this module (numbers, text and None, conversions, input and output)

What you are building

four answers in, one row out Four answers as text Convert int(), or Days late max(..., 0) Fee in pence min(..., 300) L13 Ben 35 True 9 180 one row per loan; six loans make the table
The calculator takes a loan's four parts as text (amber: typed, so uncertain), converts and works them out (blue), and prints one checked row (green).

Amira's question for this module was "What does Ben owe if he is 9 days late?" You answered it in Lesson 1 with the 9 written into the code. Now you build the calculator she can use for any loan. It takes the four facts on a loan line as text: the loan id, the member, the borrow day and the return day (blank if the book is still out). It converts them, works out the due day, the days late and the fee in whole pence, capped at 300, and prints one row of a table.

You build it first in notebook cells for Ben's loan L13, then save it as a script and feed it six loans from the shelf: L02, L04, L05, L07, L13 and L23. A check cell then compares the six rows with the right answers. Every loan and person here is simulated. Open a new Colab notebook for the lab and run the cells 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.