Question Description
You are writing an inventory system for a library. This program will allow the user to enter a book, remove a book, and find a book. The book titles will be stored in a dictionary. Each key in the dictionary is a books title, and each value is the number of copies currently in stock.
In a continuous loop, give the user the option to add a book, remove a book, find a book, and quit.
- If the user chooses to add a book, call a function named add_book. This function should ask the user for a book title. If the title is not in the dictionary, add it with a value of 1 to indicate there is now a single copy of that book in stock. If it is in the dictionary, update its value to indicate that another copy is now in stock.
- If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the books title exists in the dictionary, print out how many copies of it are currently in stock. Otherwise, print that no copies are in stock.
- If the user chooses to remove a book, call a function named remove_book. In this function, ask the user to enter a title. If the title exists in the dictionary, remove a single copy. If there are no more copies in stock, remove the key/value pair from the dictionary. Hint: You may want to refer to the very end of lecture 12 for info on how to remove a specific key/value pair from a dictionary.
If the user chooses quit, write all of the dictionary’s information to a text file (i.e. store each book’s name as well as how many copies of that book the library has in stock). Hint: Don’t append! When the program starts, the data from the text file should be loaded into the dictionary (if the file exists).