From c9ec33e18d03ba55e97797610a340a371013b417 Mon Sep 17 00:00:00 2001 From: Selaseyjr Date: Sat, 17 Jan 2026 15:28:43 +0100 Subject: [PATCH] week1lab2 Done --- lab-python-flow-control.ipynb | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..c094aee 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,55 @@ "\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\")." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7723426d", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "products = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set() \n", + "while True:\n", + " product_name = input(\"Enter a product to order: \")\n", + " \n", + " if product_name not in products:\n", + " print(\"Sorry, we don't have that product. Try again.\")\n", + " continue\n", + " \n", + " customer_orders.add(product_name)\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + " print(\"\\nCustomer Orders:\")\n", + "for item in customer_orders:\n", + " print(item)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered}%\")\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1 \n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] } ], "metadata": {