From 1d6d60eb03464508f658634636658c2a2790f5cb Mon Sep 17 00:00:00 2001 From: davherdel Date: Fri, 15 Aug 2025 23:47:38 +0100 Subject: [PATCH] Add files via upload --- lab-python-flow-control.ipynb | 86 ++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..5c593ae 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,93 @@ "\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": 2, + "id": "6ddd038c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter available quantity for each product:\n", + "\n", + "Customer ordered the following products:\n", + "- mug\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.00%\n", + "\n", + "Updating inventory...\n", + "\n", + "Updated Inventory:\n", + "T-shirt: 3\n", + "Mug: 1\n", + "Hat: 4\n", + "Book: 3\n", + "Keychain: 4\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "print(\"Enter available quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " order = input(\"\\nEnter a product to order: \").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"That product is not in the list. Please choose from:\", \", \".join(products))\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "\n", + "print(\"\\nCustomer ordered the following products:\")\n", + "for item in customer_orders:\n", + " print(\"-\", item)\n", + "\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "\n", + "print(\"\\nUpdating inventory...\")\n", + "for item in customer_orders:\n", + " if item in inventory and inventory[item] > 0:\n", + " inventory[item] -= 1\n", + " elif item in inventory:\n", + " print(f\"No stock left for {item}.\")\n", + " else:\n", + " print(f\"{item} is not in inventory.\")\n", + "\n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product in products:\n", + " print(f\"{product.capitalize()}: {inventory[product]}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +137,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,