Implement a Python application for managing a bookstore’s inventory. The application should allow adding books, finding highest-rated books, and recommending books by genre.
There are two classes:
Bookclass with attributes:title(string): the book’s titlegenre(string): the book’s genrerating(float): the customer rating
LibraryManagementclass with methods:add_book(Book book): adds a new book to the inventoryget_highest_rated_books(int x): returns thexhighest-rated books, sorted by rating (descending) and title (descending) for tiesrecommend_top_book_by_genre(string genre): returns the highest-rated book in the specified genre, orNoneif no books exist in that genre
The code for reading input, calling methods, and producing output is already provided.
Constraint: The number of recommended books is less than or equal to the number of books in the book list.
This problem asks you to build a bookstore inventory manager with two main operations: retrieving the top-rated books globally and recommending the best book within a genre. A common approach is to store all books in a heap or sorted structure for the global top-x query, while keeping a hash map from genre to the current best book for fast genre-based recommendations. Pay close attention to tie-breaking: higher rating comes first, and if ratings are equal, compare titles consistently as required by the prompt.