CoursePython from Scratch to Intermediate · Module 9: Classes and Objects · part 64 of 75
Part 64 · Module 9: Classes and Objects

Lab: Lend and return books with classes

23 min read·14 Oct 2026
Module 9 · Lab · About 60 minutes · Needs: lessons 1 to 4 of this module, and the Module 8 lab (the booknook folder in your Drive, with storage.py)

What you are building

STORAGE.PY ANSWERS load_books load_members load_loans models.py Book Member Loan dataclasses Library 9 of 27 out len(library) 4 overdue, 580p overdue(today) a 4th book refused a return fee to the jar
storage.py's loaders (grey) feed models.py (blue); the Library reports the shelf, refuses a fourth book (red) and takes returns (green).

Amira's request for this module is "Lend and return books properly." The four lessons built the parts: classes with __init__ and methods (Lesson 1), a Library that holds the books and refuses a fourth loan (Lesson 2), objects that print, compare and sort (Lesson 3), and dataclasses with type hints (Lesson 4).

This lab joins them into the project's new module, booknook/models.py, with the four names the course fixed: Book, Member and Loan as dataclasses, and Library, a plain class that guards the rules. The library is built from storage.py's three loaders, so it starts from the real files: 9 of 27 copies out, 4 loans overdue, 580 pence owed. Then it lends and takes back books at the counter.

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