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 book’s 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 for a book title and how many copies the user is adding. If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding. If the title is already in the dictionary, update its value to include the copies the user is adding. If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s 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 (unless there are 0 in stock, in which case tell the user the removal cannot happen and return). After removal, if there are no more copies in stock, ask the user if they would like to keep the book in the system with its amount set to 0 or if they would like to remove it from inventory altogether. Hint: If the user chooses to remove the key/value pair from the dictionary, 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.
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 book’s 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 for a book title and how many copies the user is adding. If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding. If the title is already in the dictionary, update its value to include the copies the user is adding. If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s 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 (unless there are 0 in stock, in which case tell the user the removal cannot happen and return). After removal, if there are no more copies in stock, ask the user if they would like to keep the book in the system with its amount set to 0 or if they would like to remove it from inventory altogether. Hint: If the user chooses to remove the key/value pair from the dictionary, 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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
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 book’s 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 for a book title and how many copies the user is adding.
- If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding.
- If the title is already in the dictionary, update its value to include the copies the user is adding.
- If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s 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 (unless there are 0 in stock, in which case tell the user the removal cannot happen and return).
- After removal, if there are no more copies in stock, ask the user if they would like to keep the book in the system with its amount set to 0 or if they would like to remove it from inventory altogether. Hint: If the user chooses to remove the key/value pair from the dictionary, 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.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education