From a6c982572c87b4afca71183a154cc94d1b3f438f Mon Sep 17 00:00:00 2001 From: carmamenriosrodriguez Date: Tue, 13 Jan 2026 15:23:44 +0100 Subject: [PATCH] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 80 ++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..67d1ab2 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,87 @@ "\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": 32, + "id": "4b0c822f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 47, 'mug': 384, 'hat': 38, 'book': 299, 'keychain': 29}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products: \n", + " amount = int(input(f\"How many products are of {product}?\"))\n", + " inventory[product] = amount\n", + " \n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "32638449", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thank you for your order! :)\n", + "{'mug', 'book'}\n" + ] + } + ], + "source": [ + "\n", + "costumer_orders = set()\n", + "petition = \"Yes\".lower()\n", + "\n", + "while petition == \"Yes\".lower():\n", + " order = input(\"Write a product to order\")\n", + " costumer_orders.add(order)\n", + " petition = input(\"Do you want to order another product? (Yes/No)\").lower()\n", + "\n", + " \n", + "print(\"Thank you for your order! :)\")\n", + "print(costumer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "8c6abde8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 47, 'mug': 383, 'hat': 38, 'book': 298, 'keychain': 29}\n" + ] + } + ], + "source": [ + "\n", + "for product in costumer_orders:\n", + " inventory[product] -= 1 \n", + "print(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ds", "language": "python", "name": "python3" }, @@ -55,7 +131,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.12" } }, "nbformat": 4,