Lab | Data Structures¶
+Exercise: Managing Customer Orders¶
As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.
+Follow the steps below to complete the exercise:
+-
+
Define a list called
+productsthat contains the following items: "t-shirt", "mug", "hat", "book", "keychain".
+Create an empty dictionary called
+inventory.
+Ask the user to input the quantity of each product available in the inventory. Use the product names from the
+productslist as keys in theinventorydictionary and assign the respective quantities as values.
+Create an empty set called
+customer_orders.
+Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of "t-shirt", "mug", "hat", "book" or "keychain". Add each product name to the
+customer_ordersset.
+Print the products in the
+customer_ordersset.
+Calculate the following order statistics:
+-
+
- Total Products Ordered: The total number of products in the
customer_ordersset.
+ - Percentage of Products Ordered: The percentage of products ordered compared to the total available products. +
Store these statistics in a tuple called
+order_status.
+- Total Products Ordered: The total number of products in the
Print the order statistics using the following format:
+
+Order Statistics: +Total Products Ordered: <total_products_ordered> +Percentage of Products Ordered: <percentage_ordered>% +
+Update the inventory by subtracting 1 from the quantity of each product. Modify the
+inventorydictionary accordingly.
+Print the updated inventory, displaying the quantity of each product on separate lines.
+
+
Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations.
+products = ["t-shirt", "mug", "hat", "book", "keychain"]
+inventory = {}
+quantity = int(input(f"Enter the quantity for {product}: "))
+customer_orders = set()
+for _ in range(3):
+ order = input("Enter the product name: ").lower()
+ if order in products:
+ customer_orders.add(order)
+ else:
+ print("Product not available.")
+
+Product not available. +Product not available. +Product not available. ++
print("Products in customer orders:", customer_orders)
+Products in customer orders: set() ++
total_products_ordered = len(customer_orders)
+percentage_ordered = (total_products_ordered / len(products)) * 100
+order_status = (total_products_ordered, percentage_ordered)
+