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
icon
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Basics of loop
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education