Mini Library Lending System

Hard ⏱ 18 min 30% acceptance ★★★★★ 4.8
Design two cooperating classes: Member(name) with a borrowed list, and Library seeded with a dict of title → copy count. Library.lend(title, member) decrements stock and appends to the member's list, returning True; it returns False when out of stock or unknown. Library.give_back(title, member) reverses it (only if the member actually holds the title).

Examples

Example 1
Input
lib = Library({'Dune': 1}); m = Member('Ana'); lib.lend('Dune', m); lib.lend('Dune', Member('Raj'))
Output
True then False
Explanation

The single copy went to Ana; Raj is refused.

Constraints

  • Stock never goes negative.
  • give_back only works for actual holders.

Topics

OOPmulti-class design

Companies

AmazonGoogleThoughtWorks

Hints

Hint 1

The library mutates both its stock and the member object.

Hint 2

Guard clauses keep each method short.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.