#C8722. Inventory Management System
Inventory Management System
Inventory Management System
The task is to implement an inventory management system. You will design a class (or equivalent data structure) to manage product stock levels. The system supports the following commands:
add_product <product>
: Increase the inventory count for the given product by 1. If the product does not exist, it is added with an initial count of 1.ship_product <product>
: Decrease the inventory count for the given product by 1. If the product's count becomes 0, remove the product from the inventory. If the product does not exist, an error should be raised, displaying:
Product 'product
' not found in inventory.current_inventory
: Print the current inventory in the Python dictionary format. For example, if the inventory has one apple and two bananas, print{'apple': 1, 'banana': 2}
.
Note: The internal update rules can be mathematically described as follows: if we denote the inventory count of a product p by \(I(p)\), then:
\[ I(p) \leftarrow I(p) + 1 \quad \text{when executing } add\_product(p), \] \[ I(p) \leftarrow I(p) - 1 \quad \text{when executing } ship\_product(p), \]with the condition that if \(I(p) = 0\) then the product is removed from the inventory.
inputFormat
The input is given from standard input (stdin). Each line contains a command. A command is one of the following:
add_product <product>
ship_product <product>
current_inventory
The input terminates when an empty line or EOF is encountered.
outputFormat
The output is produced on standard output (stdout) only when the command current_inventory
is executed. The inventory should be printed in Python dictionary format. For example:
{'apple': 1, 'banana': 2}## sample
add_product apple
current_inventory
{'apple': 1}