Professional Documents
Culture Documents
Create a console based inventory management system in python language in which you needs to
import json and create a blank dictionary named inventory and you have to display 5 options for a
user to choose one.
============================================================================
============================================================================
Function # 1
Create a function to add a new product in which you have to take input in the following variables
1) product_id
2) product_name
3) stock
Assign p1 to the inventory dictionary with product_id as a key then dump the inventory
dictionary to an inventory.json file.
Code Hint
inventory[product_id] = p1
============================================================================
Function # 2
Create a function to add stock of the item in which you have to take input the product_id and stock
to be added in the following variables
1) product id
2) add_stock
Open an inventory.json file to read its data and search the corresponding product_id in the
retrieved inventory dictionary to access the stock against the product_id.
Code Hint
inventory = json.load(file_handle)
INVENTORY MANAGEMENT SYSTEM
(PYTHON FINAL PROJECT) - HADI
Add the new stock to the accessed stock and replace it to the position.
Code Hint
inventory[product_id][“ stock”] += add_stock
Again open an inventory.json file for writing purpose and dump the updated inventory dictionary
to the file.
============================================================================
Function # 3
Create a function to sell stock for which you have to take input the product_id and stock to be sold
in the following variables
1) product id
2) sell_stock
Open a inventory.json file to read its data and search the corresponding product_id in the
retrieved inventory dictionary to access the stock against the product_id.
Deduct the sell_stock from the accessed stock and replace it to the position.
Code Hint
inventory[product_id][“ stock”] -= sell_stock
Again open an inventory.json file for writing purpose and dump the updated inventory dictionary
to the file.
============================================================================
Function # 4
Create a function to view product of the inventory for which you have to take input the
product_id.
Open inventory.json file to read its data and search the corresponding product_id in the retrieved
inventory dictionary to access the product_name & stock against the product_id.
Display the product_name & stock.
============================================================================
NOTE: Repeat the process using while loop by setting Flag until user give input on each function to
end the program.
Best of luck