From 4e36459ddab13930e8f8d1f2756a378c47e19eaa Mon Sep 17 00:00:00 2001 From: titijoli2-ai Date: Tue, 26 May 2026 00:06:26 +0200 Subject: [PATCH] Add files via upload --- lab-python-flow-control.ipynb | 110 +++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..8e6b467 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,114 @@ "\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": "05dbb288-0ce4-4b2c-ab9e-e7692b2b1c67", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "054cb3dc-db4b-46d9-bb51-db830ddd6ccf", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "products_list=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f92043e8-8da0-44aa-af21-a79c681675d6", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "please enter the name of a product you want to order mug\n", + "Do you want to add another product ? Yes or No no\n" + ] + } + ], + "source": [ + "customers_order = set()\n", + "while True:\n", + " product = input(\"please enter the name of a product you want to order\")\n", + " customers_order.add(product)\n", + " answer = input(\"Do you want to add another product ? Yes or No\")\n", + " if answer.lower ()!= \"yes\" :\n", + " break\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "d3a6c6d2-95c7-49d7-aea8-203de8f30621", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory: {'t-shirt': 31, 'mug': 11, 'hat': 25, 'book': 7, 'keychain': 10}\n" + ] + } + ], + "source": [ + "inventory_dict = {'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7, 'keychain': 10}\n", + "\n", + "for product in customers_order:\n", + " if product in inventory_dict:\n", + " inventory_dict[product] -= 1\n", + " print(\"Updated inventory:\", inventory_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f043c69-2c37-428c-adc7-64818554a24e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43e8015e-8cfe-4de2-800c-f7a64236a9f1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23092814-483f-4e6b-b5fa-6a92fe5aee69", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a11c4dbb-5760-4654-b014-38c3c898cec4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd13b6fb-f3fc-4593-a39c-b03b2a28479b", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +163,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.11" } }, "nbformat": 4,