From f4b8d8eb321a90ccea72a9b5c4f6207cca45f61a Mon Sep 17 00:00:00 2001 From: andressa Date: Fri, 16 Jan 2026 13:48:26 +0000 Subject: [PATCH] lab2 --- lab-python-flow-control.ipynb | 47 +++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..dc274c2 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,54 @@ "\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": 15, + "id": "57394a05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory {'t-shirts': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n", + "Customer's unique orders: {'hat', 'mug'}\n", + "Updated inventory: {'t-shirts': 5, 'mug': 4, 'hat': 4, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "products = [\"t-shirts\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for item in products:\n", + " quantity = int(input(f\"Please enter the quantity for {item}: \"))\n", + " inventory[item] = quantity\n", + "\n", + "print(\"Inventory\", inventory)\n", + "\n", + "customers_orders = set()\n", + "\n", + "continue_ordering = \"yes\"\n", + "while continue_ordering == \"yes\":\n", + " order = input(\"Please enter the product you want to order:\" )\n", + " customers_orders.add(order)\n", + "\n", + " continue_ordering = input(\"Do you want to order another product? (yes/no): \")\n", + "\n", + "print(\"Customer's unique orders:\", customers_orders)\n", + "\n", + "for item in customers_orders:\n", + " if item in inventory:\n", + " inventory[item] -= 1\n", + "print(\"Updated inventory:\", inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +98,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,