CoursePython from Scratch to Intermediate · Module 4: Decisions and Loops · part 30 of 75
Part 30 · Module 4: Decisions and Loops

Lab: Label twelve loans and total the fees

12 min read·14 Oct 2026
Module 4 · Lab · About 45 minutes · Needs: lessons 1 to 3 of this module, Module 3 (split, splitlines, f-strings) and Module 2 (int(), +=, min())

What you are building

TWELVE LOANS, LABELLED ON DAY 44 L01 on time L02 back late L04 overdue L05 on time L07 back late L12 on time L13 overdue L21 overdue L23 overdue L24 due soon L28 out L30 on time owed 580p 4 overdue jar 140p 2 returned late remind 5 overdue or due soon
One pass labels every loan (red overdue, amber due soon, blue out, green on time, grey returned late) and totals 580p owed and 140p in the jar.

Amira's question for this module is "Which of these twelve loans are overdue?" Each lesson answered a piece of it. Lesson 1 labelled one loan at a time, Lesson 2 walked all twelve with a for loop and totalled what is owed, and Lesson 3 counted late days with a while loop and stopped searches early with break.

This lab puts the pieces together in one notebook. You walk the twelve loans once, give each one a label (overdue, due soon, out, returned on time or returned late), work out its fee, and print a lined-up list for Amira with three totals: 580 pence owed, 140 pence already in the fee jar, and five loans that need a reminder. Then you check the answers two ways and look a loan up by its id.

Open a new Colab notebook, call it module-04-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.