diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..0e02e70 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -35,7 +35,43 @@ " \n", " d. Continue the loop until the user does not want to add another product.\n", "\n", - "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." + "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\").\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter a product name: \").lower()\n", + " \n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not available. Please choose from the list.\")\n", + " continue\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "total_unique_orders = len(customer_orders)\n", + "percentage_unique_orders = (total_unique_orders / len(products)) * 100\n", + "\n", + "print(f\"Total unique products ordered: {total_unique_orders}\")\n", + "print(f\"Percentage of unique products ordered: {percentage_unique_orders:.2f}%\")\n", + "\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "print(\"Updated inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" ] } ],