Learn how to create a basic shop management system using Python. This tutorial provides example code and step-by-step instructions for adding, viewing, and removing products from the shop’s inventory.
Problem Python Program
You need to create a shop management system in Python that can add, view, and remove products from the inventory.
Example Code
products = {}
while True:
print("\nShop Management System\n")
print("1. Add product")
print("2. View products")
print("3. Remove product")
print("4. Exit")
choice = input("\nEnter your choice (1-4): ")
if choice == "1":
name = input("\nEnter product name: ")
price = float(input("Enter product price: "))
quantity = int(input("Enter product quantity: "))
products[name] = {"price": price, "quantity": quantity}
print("\nProduct added successfully")
elif choice == "2":
if len(products) == 0:
print("\nNo products found")
else:
print("\nList of products:")
for name, details in products.items():
print(f"{name} (Price: {details['price']}, Quantity: {details['quantity']})")
elif choice == "3":
if len(products) == 0:
print("\nNo products found")
else:
name = input("\nEnter product name to remove: ")
if name in products:
del products[name]
print("\nProduct removed successfully")
else:
print("\nProduct not found")
elif choice == "4":
print("\nExiting program")
break
else:
print("\nInvalid choice, please enter a valid choice (1-4)")
Excepted output
Shop Management System 1. Add product 2. View products 3. Remove product 4. Exit Enter your choice (1-4): 1 Enter product name: Apple Enter product price: 0.5 Enter product quantity: 10 Product added successfully Shop Management System 1. Add product 2. View products 3. Remove product 4. Exit Enter your choice (1-4): 2 List of products: Apple (Price: 0.5, Quantity: 10) Shop Management System 1. Add product 2. View products 3. Remove product 4. Exit Enter your choice (1-4): 3 Enter product name to remove: Apple Product removed successfully Shop Management System 1. Add product 2. View products 3. Remove product 4. Exit Enter your choice (1-4): 4 Exiting program
Explanation:
This program provides a menu-based interface for managing a shop’s inventory. The program uses a dictionary called products
to store the details of each product. The program allows the user to add a product to the inventory by providing the name, price, and quantity of the product. The program allows the user to view the list of products in the inventory and remove a product from the inventory. The program exits when the user chooses to exit the program. The output shows the various options available to the user and the expected output for each option.