From b27a928e79d275c025c96c21892f88c7e704ba7f Mon Sep 17 00:00:00 2001 From: riverapablo1988 Date: Fri, 10 Oct 2025 10:45:04 -0500 Subject: [PATCH] Lab 2 done --- lab-python-flow-control.ipynb | 39 ++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..c1cd791 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,13 +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": "645de7a2-8872-45de-ac02-4c9335f28ab6", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " qty = int(input(f\"Enter # of {product}: \"))\n", + " inventory[product] = qty\n", + "\n", + "customer_orders = set()\n", + "\n", + "add_another = \"yes\"\n", + "\n", + "while add_another==\"yes\":\n", + " product_name = input(\"Enter the name of a product that a customer wants: \")\n", + " customer_orders.add(product_name)\n", + "\n", + " add_another = input(\"Do you want to continue to order products? (yes/no)\")\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -=1\n", + "\n", + " print(\"products in customer orders: \", customer_orders)\n", + "\n", + " print(\"Updated inventory: \", inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -55,7 +88,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,