Project 12 of 20, for Neil
Library Manager
Loans and reference copies for Neil's racing and space books on the Studio shelves, with Yahya and Caitlin arguing about whether a library is a kind of list.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- NeilMy racing and space books live on the Studio shelves, but nothing says which ones are out or who's got them.
- NeilI asked Yahya and Caitlin to write me something and they've been arguing by the kettle for an hour.
- YahyaLook, a reference book is a book and a library is a list of books, it's that simple.
- CaitlinA library isn't a list though, it has books in it, and rules.
- PaulYou're each right about one thing. Write it and you'll find out which.
In library.py, with type hints throughout:
Status, anEnumwith two members:ON_SHELF("on the shelf") andON_LOAN("on loan").Book, a dataclass:title,author,year, thenstatus(defaultStatus.ON_SHELF) andborrower(defaultNone).lend(member)puts it on loan tomemberand returnsTrue. If it's already on loan, it changes nothing and returnsFalse.give_back()puts it back on the shelf, with no borrower.str(book)givesCarrying the Fire, Michael Collins (1974): on loan.
ReferenceBook, a kind ofBookthat never leaves the library:lendalways returnsFalse, and it shows itself as a book does, then, reference only, building onBook's line withsuper().Library, which has books, kept in a list calledbooks:add(book)adds it and returnsTrue, unless a book with that title is already there, whatever its capitals: thenFalse.find(title)returns the book with that title, whatever its capitals, orNone.on_shelf()returns the books that aren't on loan, in the order they were added.len(library)is how many books it has.
The library has 3 books Carrying the Fire, Michael Collins (1974): on loan House Style, Paul (2025): on the shelf, reference only On the shelf: The Mechanic's Tale, House Style
What you learn
What's in it
- A class that writes itself
- A class that writes itself
- Notes on what goes where
- Notes, not rules
- A fixed set of choices
- On the shelf, or not
- How Paul would keep a record
- A kind of something
- A kind of book
- Let the parent do its part
- A setup that never ran
- Has a, or is a
- Caitlin's way
- How Paul would do it
- Fix Aaesha's version
- Make the library
- Ship it