From 9c7405a5e43736b3f8852d12f279a0a21608bb51 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jun 2025 23:44:16 +0200 Subject: [PATCH] Lab Solved --- lab-python-flow-control.ipynb | 98 ++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..13cd2f7 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,102 @@ "\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": 16, + "id": "96699be1-9322-4775-a48c-aadea0c9b071", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 10\n", + "Enter the quantity for mug: 50\n", + "Enter the quantity for hat: 4\n", + "Enter the quantity for book: 10\n", + "Enter the quantity for keychain: 40\n", + "Enter customer product: mug\n", + "Add another product? (yes/no): yes\n", + "Enter customer product: hat\n", + "Add another product? (yes/no): yes\n", + "Enter customer product: t-shirt\n", + "Add another product? (yes/no): yes\n", + "Enter customer product: keychain\n", + "Add another product? (yes/no): no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order: {'mug', 't-shirt', 'keychain', 'hat'}\n", + "\n", + "Order Statistics: 5\n", + "Total Products Ordered: 4\n", + "Percentage of Products Ordered: 80.0 %\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 9\n", + "mug: 49\n", + "hat: 3\n", + "book: 10\n", + "keychain: 39\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "for product in products:\n", + " quantity = int(input(\"Enter the quantity for \" + product + \": \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product_name = input(\"Enter customer product: \").strip()\n", + " if product_name in products:\n", + " customer_orders.add(product_name)\n", + " else:\n", + " print(\"Not in inventory\")\n", + " \n", + " another = input(\"Add another product? (yes/no): \").strip()\n", + " \n", + " if another != \"yes\":\n", + " break\n", + " \n", + "\n", + "print(\"\\nOrder: \", customer_orders)\n", + "\n", + "Total_Products_Ordered = len(customer_orders)\n", + "Total_Products = len(products)\n", + "Percentage_of_products_ordered = (Total_Products_Ordered/Total_Products)*100\n", + "\n", + "order_status = (Total_Products_Ordered, Total_Products, Percentage_of_products_ordered)\n", + "\n", + "print(\"\\nOrder Statistics: \", Total_Products)\n", + "print(\"Total Products Ordered: \", Total_Products_Ordered)\n", + "print(\"Percentage of Products Ordered: \", Percentage_of_products_ordered, \"%\")\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] = inventory[product] - 1\n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product in inventory:\n", + " print(product + \": \" + str(inventory[product]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "972d99d9-eac6-41aa-8617-ddfc7566e42b", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +151,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,