From 5e4a4c4cab58af17e871f988a94f4c6f7b143183 Mon Sep 17 00:00:00 2001 From: arnaumatasfont-keky Date: Tue, 14 Apr 2026 14:43:39 +0200 Subject: [PATCH] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..8957e41 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,69 @@ "\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": "f0a0b6e2", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {\"t-shirt\": 10,\"pants\": 5,\"shoes\": 3,\"jacket\": 2}\n", + "\n", + "costumers_order = set()\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36af25f1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pants added to your order.\n", + "Your order includes the following products: {'pants'}\n", + "\n", + "Inventory after processing the order:\n", + "t-shirt: 10 units left\n", + "pants: 4 units left\n", + "shoes: 3 units left\n", + "jacket: 2 units left\n", + "\n", + "Final inventory status: {'t-shirt': 10, 'pants': 4, 'shoes': 3, 'jacket': 2}\n" + ] + } + ], + "source": [ + "add_product = \"yes\"\n", + "\n", + "while add_product.lower() == \"yes\":\n", + " product = input(f\"Enter the product you want to order(Items available: {list(inventory.keys())}): \").lower()\n", + " if product in inventory:\n", + " costumers_order.add(product)\n", + " print(f\"{product} added to your order.\")\n", + " else:\n", + " print(\"Product not found in inventory.\")\n", + "\n", + " add_product = input(\"Do you want to add another product? (yes/no): \")\n", + "print(f\"Your order includes the following products: {costumers_order}\")\n", + "\n", + "print(\"\\nInventory after processing the order:\")\n", + "for item, quantity in inventory.items():\n", + " if item in costumers_order:\n", + " inventory[item] -= 1 # Assuming one unit of each product is ordered\n", + " print(f\"{item}: {inventory[item]} units left\")\n", + "print(f\"\\nFinal inventory status: {inventory}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -55,7 +113,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,