#C14019. Library Book Management System
Library Book Management System
Library Book Management System
In this problem, you need to implement a simple library management system using two dictionaries: library_books
and borrowed_books
. You must implement the following operations:
- ADD book_title: Add a book to the library. This can be modeled as increasing the count of that book in
library_books
. In mathematical terms, if you denote the count of a book by \( library\_books[book\_title] \), then after adding a book, the update is: $$ library\_books[book\_title] = library\_books.get(book\_title,0) + 1 $$ - BORROW book_title user_name: A user attempts to borrow a book. If the book is available (i.e. its count in
library_books
is at least 1), then decrease the count by 1 and record the borrowing inborrowed_books
with the user name. Print a success message in the format:{user_name} has borrowed {book_title}
. If the book is not available, printBook not available
. - RETURN book_title: A user returns a book. If the book is currently borrowed (exists in
borrowed_books
), remove it fromborrowed_books
, add it back to the library (i.e. increase its count inlibrary_books
), and print a message:{user_name} has returned {book_title}
(using the recorded user name). Otherwise, printThis book was not borrowed
.
After processing all commands, you should output the final state of library_books
and borrowed_books
as their dictionary representations.
inputFormat
The first line of input contains an integer T
representing the number of operations. Each of the following T
lines contains a command in one of the following forms:
ADD book_title
BORROW book_title user_name
RETURN book_title
Note: In the test cases provided, book_title
and user_name
will be a single word without spaces.
outputFormat
For each command that produces an output (i.e. the BORROW
and RETURN
commands), print the corresponding message. After processing all commands, output the final state of library_books
and borrowed_books
dictionaries (each on a new line) using Python dictionary format.
3
ADD TheGreatGatsby
ADD 1984
BORROW 1984 Alice
Alice has borrowed 1984
{'TheGreatGatsby': 1}
{'1984': 'Alice'}
</p>