From 59f633b661cdddbd9b0745f828309947051140ba Mon Sep 17 00:00:00 2001 From: FatmaCakir Date: Tue, 15 Sep 2026 18:58:36 +0300 Subject: [PATCH] Solved flow control lab --- lab-python-flow-control.ipynb | 60 +++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..8db1d33 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -10,6 +10,62 @@ "# Lab | Flow Control" ] }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e1c0625a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer Orders: {'book'}\n", + "\n", + "Updated Inventory:\n", + "t-shirt : 10\n", + "mug : 12\n", + "hat : 15\n", + "book : 19\n", + "keychain : 18\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " order = input(\"Enter a product you want to order: \")\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Product not available.\")\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \").lower()\n", + "\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "print(\"Customer Orders:\", customer_orders)\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] + }, { "cell_type": "markdown", "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", @@ -41,7 +97,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +111,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.7" } }, "nbformat": 4,