From d190ad064b933154c919cd571a0b995e69e40326 Mon Sep 17 00:00:00 2001 From: baharmnb Date: Sat, 7 Mar 2026 15:59:16 +0100 Subject: [PATCH] lab solved --- .DS_Store | Bin 0 -> 6148 bytes lab-python-flow-control.ipynb | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f9a65cf97a114492b620c344acd6dc58c0278cd9 GIT binary patch literal 6148 zcmeHKu};H441F#cidZ_bRLT!f#2=(pIxw)n4?tQ`Duo82AjFoB;D6!SJ`gFH7?41= zboYGr*||I^=NN!2p4Ml;1i+X>QB)ZaH4nN*Y4ZV5G{6grh zxWp23l(--{v3>Tat;AAZTF{9apy8ZeSb2Si)gq w!M*si- literal 0 HcmV?d00001 diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..6e12a69 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,46 @@ "\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": "3ace3f95-0633-4b62-8d82-fdcc48e29bdb", + "metadata": {}, + "outputs": [], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory={} \n", + "\n", + "for x in products:\n", + " qnt =input (f\" Enter the inventory quantity of {x}: \")\n", + " inventory[x] = int(qnt)\n", + " \n", + "customer_orders = set()\n", + "answer=\"yes\"\n", + "\n", + "while answer == \"yes\" : #2-d\n", + " product = input(\"Enter a product (t-shirt, mug, hat, book, keychain): \") #2-a\n", + " if product in products:\n", + " customer_orders.add(product) #2-b\n", + " else:\n", + " print(\"Invalid product. Please enter one of the listed products.\")\n", + " answer = input(\"Do you want to add another product? (yes/no): \") #2-c\n", + "\n", + "for product in customer_orders: #3\n", + " inventory[product] -= 1\n", + " print(product, inventory[product])\n", + " \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3531d6c1-e445-4b36-9940-ab5ab8738fb3", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +95,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.6" } }, "nbformat": 4,