""" ################################################################################ FINAL EXAM RULES ################################################################################ - You are strictly forbidden to share answers with your classmates. - You are not allowed to search for answers on the Internet. You are not allowed to ask for answers in forums or other online communication systems. - Note that, when you find an answer on the web, somebody else will also find it and use it. This means, both of you will submit the exact same answer. This, then, means cheating, no matter you know the other person or not. - If your answers are similar to some other student's answers, you will enter manual cheat check process. We don't care whether you know the other person or not, we don't care whether he/she is your friend or not, we don't care who delivered and who received. Both parties get a discipline penalty if found guilty. - You are not allowed to import any packages. If there are any imports in your submission, we will remove them before grading. - If your file doesn't run, then you will get 0 points. Make sure that your indentation and syntax are correct. - Do not change the given function definitions. In other words, DO NOT CHANGE the function names and the parameters of the functions. You are only allowed to write code within the function scope. - Do not print anything on the screen unless you are asked to. Some questions require you to RETURN a value. Printing that value on the screen is not equal to returning the value. The reverse is also true: if a function is supposed to print a value, then make sure you print it, not return it. - Do not submit any testing code! Submit only your class implementation! - Do not try to take user input using Python input() function! The automated tests will provide inputs to your functions for grading, not some user. ################################################################################ DO NOT FORGET TO FILL THE LINES BELOW: My full name : _______________ My student ID : _______________ My department : _______________ """ """ ################################################################################ Question 1: (100 points) Library Catalog Class ################################################################################ Create a Python class called LibraryCatalog that represents a catalog for a library. The class should have the following attributes and methods: ---------------------------------Attributes--------------------------------- -------------- name (string): -------------- A string that represents the name of the library catalog. ------------- books (list): ------------- A list to store the books in the library catalog. Each book will be represented as a dictionary with the following keys: 'title', 'author', and 'year'. ----------------------------------Methods----------------------------------- --------------------- __init__(self, name): --------------------- Instantiates a new empty Library Catalog object under the given name. -------------- __str__(self): -------------- Returns a string representation of the LibraryCatalog object, displaying all books in the catalog in a readable format as explained below: - If the catalog is empty, this method should return the message: The catalog '' is empty. - If the catalog is not empty, it should return a string representation in the following format: Catalog '': Title: , Author: , Year: Title: , Author: , Year: ... and so on for each book in the catalog. Here, is the name of the catalog, is the title of the first book in the catalog, is the name of the author of this book, is the year of this book's publication, and so on. ------------------------------------ add_book(self, title, author, year): ------------------------------------ Adds a new book to the library catalog with the given title, author, and year, and PRINTS an info message in the following format: Added book '' to the catalog ''. where is the title of the added book and is the name of the catalog to which the book is added. ------------------------- remove_book(self, title): ------------------------- Removes the book with the given title from the library catalog if found, and PRINTS an info message in the following format: - if the book was in the catalog it should print: Removed book '' from the catalog ''. - if the book was not in the catalog it should print: Book '' not found in the catalog ''. where is the title of the book, and is the name of the catalog. ------------------------- search_book(self, title): ------------------------- Searches for a book with the given title in the library catalog and returns its details (title, author, and year) if found in the following format: Book found: Title: , Author: , Year: where is the title of the book, is it's author's name, and is the year the book was publlished in. If the book is not found, it should return a message in the following format: Book '' not found in the catalog. where <title> is the title of the searched book. -------------------------------------- compare_catalogs(self, other_catalog): -------------------------------------- Compares two catalogs and returns the list of the books they have in common. -------------------- group_by_year(self): -------------------- Groups the books by years and returns a dictionary where keys are years and values are lists of books published that year. ------------------------------- search_by_author(self, author): ------------------------------- Returns a list of book titles written by the author. If there are no books by the given author in the catalog, it should return a message in the following format: No books found by <author>. where <author> is the given author name. -------------------------Instructions for testing--------------------------- Write the LibraryCatalog class with the appropriate attributes and methods as described above. Test your class by performing the following operations: # Testing the LibraryCatalog class catalog = LibraryCatalog("Computer Science") print(catalog) # Add some books catalog.add_book("Python Programming", "John Smith", 2019) catalog.add_book("Introduction to Algorithms", "Thomas Cormen", 2009) catalog.add_book("Data Science for Beginners", "Emily Davis", 2021) catalog.add_book("Web Development Basics", "John Smith", 2021) catalog.add_book("Data Structures and Algorithms", "Jane Doe", 2009) print(catalog) # Test searching for a book print(catalog.search_book("Python Programming")) print(catalog.search_book("Introduction to Coding")) # Test removing a book catalog.remove_book("Introduction to Algorithms") catalog.remove_book("Introduction to Coding") print(catalog) # Create a second instance of the LibraryCatalog class catalog2 = LibraryCatalog("Programming") catalog2.add_book("Python Programming", "John Smith", 2019) catalog2.add_book("Introduction to Programming", "Jane Doe", 2020) catalog2.add_book("Data Science for Beginners", "Emily Davis", 2021) # Compare two catalogs common_books = catalog.compare_catalogs(catalog2) print(common_books) # Group books by year books_by_year = catalog.group_by_year() print(books_by_year) # Search for books by author author = "John Smith" books_by_author = catalog.search_by_author(author) print(books_by_author) author2 = "Fyodor Dostoevsky" books_by_author = catalog.search_by_author(author2) print(books_by_author) ---------------------------Expected Output--------------------------- The catalog 'Computer Science' is empty. Added book 'Python Programming' to the catalog 'Computer Science'. Added book 'Introduction to Algorithms' to the catalog 'Computer Science'. Added book 'Data Science for Beginners' to the catalog 'Computer Science'. Added book 'Web Development Basics' to the catalog 'Computer Science'. Added book 'Data Structures and Algorithms' to the catalog 'Computer Science'. Catalog 'Computer Science': Title: Python Programming, Author: John Smith, Year: 2019 Title: Introduction to Algorithms, Author: Thomas Cormen, Year: 2009 Title: Data Science for Beginners, Author: Emily Davis, Year: 2021 Title: Web Development Basics, Author: John Smith, Year: 2021 Title: Data Structures and Algorithms, Author: Jane Doe, Year: 2009 Book found: Title: Python Programming, Author: John Smith, Year: 2019 Book 'Introduction to Coding' not found in the catalog. Removed book 'Introduction to Algorithms' from the catalog 'Computer Science'. Book 'Introduction to Coding' not found in the catalog 'Computer Science'. Catalog 'Computer Science': Title: Python Programming, Author: John Smith, Year: 2019 Title: Data Science for Beginners, Author: Emily Davis, Year: 2021 Title: Web Development Basics, Author: John Smith, Year: 2021 Title: Data Structures and Algorithms, Author: Jane Doe, Year: 2009 Added book 'Python Programming' to the catalog 'Programming'. Added book 'Introduction to Programming' to the catalog 'Programming'. Added book 'Data Science for Beginners' to the catalog 'Programming'. [{'title': 'Python Programming', 'author': 'John Smith', 'year': 2019}, {'title': 'Data Science for Beginners', 'author': 'Emily Davis', 'year': 2021}] {2019: [{'title': 'Python Programming', 'author': 'John Smith', 'year': 2019}], 2021: [{'title': 'Data Science for Beginners', 'author': 'Emily Davis', 'year': 2021}, {'title': 'Web Development Basics', 'author': 'John Smith', 'year': 2021}], 2009: [{'title': 'Data Structures and Algorithms', 'author': 'Jane Doe', 'year': 2009}]} ['Python Programming', 'Web Development Basics'] No books found by Fyodor Dostoevsky. """ class LibraryCatalog: # YOUR CODE GOES HERE # Remove the print line below before you answer this question. # If you do not answer this question, then do NOT remove this line below. print("I did not answer this question")