In utils/queries.py
Write a function, display_books that takes a list of books and prints them in a readable format.
Example:
>>> display_books(["1984", "The Hobbit"])
Available books:
- 1984
- The Hobbit
In utils/queries.py
Write a function, is_book_available, that takes a book title and a list of available books,
book and books, and returns True if the book is in the list of books,
otherwise False. Example:
>>> is_book_available("1984", ["1984", "The Hobbit"])
True
>>> is_book_available("Of Mice And Men", ["1984", "The Hobbit"])
False
In utils/actions.py
Write a function, borrow_book(user: str, book: str, books: list[str], borrowed: dict[str, str]),
that removes the book from the available books
and adds it to the user's borrowed list if the book is available.
Return a message about the action. Example:
>>> books = ["1984", "The Hobbit"]
>>> borrowed = {}
>>> print(borrow_book("Alice", "1984", books, borrowed))
Book '1984' borrowed by Alice.
>>> borrowed
{'Alice': ['1984']}
>>> books
["The Hobbit"]
Sorry, Of Mice And Men is not available.
In utils/actions.py
Write a function, return_book(user: str, book: str, books: list[str], borrowed: dict[str, str]),
that moves a book from a user's borrowed list back to the available books.
Return a message about the action. Example:
>>> books = ["1984", "The Hobbit"]
>>> borrowed = {'Alice': ['1984']}
>>> print(return_book("Alice", "1984", books, borrowed))
Book 1984 returned by Alice.
>>> print(return_book("Alice", "The Hobbit", books, borrowed))
Alice did not borrow 'The Hobbit.
In utils/queries.py
Write a function, display_user_books, that takes a user and the borrowed dictionary,
and prints the books borrowed by that user. Example:
>>> borrowed = {'Alice': ['1984']}
>>> display_user_books("Alice", borrowed)
Alice has borrowed:
- 1984
>>> borrowed = {}
>>> display_user_books("Alice", borrowed)
Alice has not borrowed any books.
In utils/queries.py
Write a function, search_books, that takes a keyword and a list of available books.
It should return a list of books that contain the keyword (case-insensitive). Example:
>>> books = ["The Hobbit", "Hobbiton Tales", "Python Programming"]
>>> search_books("hobbit", books)
['The Hobbit', 'Hobbiton Tales']
In utils/queries.py
Write a function, get_most_active_user, that takes the borrowed dictionary
and returns the user who borrowed the most books.
If there are multiple users with the same maximum, return any one of them. Example:
>>> borrowed = {"Alice": ["1984", "The Hobbit"], "Bob": ["Python"]}
>>> get_most_active_user(borrowed)
'Alice'
In main.py
Write a function, generate_report, that takes the list of available books and the dictionary of borrowed books, and prints a summary report with the following details:
- Total number of available books
- Total number of users who have borrowed at least one book
- Total number of books currently borrowed
- Name of the most active user (who borrowed the most books)
- A list of all currently borrowed books with the user who borrowed each
>>> books = ["Clean Code", "Design Patterns"]
>>> borrowed = {
... "Alice": ["1984", "The Hobbit"],
... "Bob": ["Python Crash Course"],
... "Charlie": []
... }
>>> generate_report(books, borrowed)
Library Report
--------------------
Available books: 2
Active users: 2
Borrowed books: 3
Most active user: Alice
Borrowed Books:
- 1984 (borrowed by Alice)
- The Hobbit (borrowed by Alice)
- Python Crash Course (borrowed by Bob)