From 96323f98515a27e2abdb04bd14443863234ac81f Mon Sep 17 00:00:00 2001 From: eliomartinezcastano-stack Date: Tue, 13 Jan 2026 15:13:23 +0100 Subject: [PATCH 1/2] final --- lab-python-flow-control.ipynb | 59 +++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..52c43c7 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,66 @@ "\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": 1, + "id": "c4f10172", + "metadata": {}, + "outputs": [], + "source": [ + "products =[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n", + "inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n", + "inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n", + "inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n", + "inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))\n", + "\n", + "customer_orders =set()\n", + "\n", + "add_another = 'yes'\n", + "while add_another == 'yes' :\n", + " product = input(\"Qué producto quieres añadir?: \") \n", + " customer_orders.add(product)\n", + " add_another = input(\"Desea seguir añadiendo?\").lower()\n", + "\n", + "\n", + "for product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "e10856f8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 9\n", + "mug: 8\n", + "hat: 9\n", + "book: 4\n", + "keychain: 5\n" + ] + } + ], + "source": [ + "print (f\"t-shirt: {inventory[\"t-shirt\"]}\")\n", + "print (f\"mug: {inventory[\"mug\"]}\")\n", + "print (f\"hat: {inventory[\"hat\"]}\") \n", + "print (f\"book: {inventory[\"book\"]}\") \n", + "print (f\"keychain: {inventory[\"keychain\"]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +110,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From 3bfde36721e0bbca4f4fd271754d2cd54ae75a9d Mon Sep 17 00:00:00 2001 From: eliomartinezcastano-stack Date: Tue, 13 Jan 2026 15:35:15 +0100 Subject: [PATCH 2/2] finalfinal --- lab-python-flow-control.ipynb | 40 ++++++----------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 52c43c7..f397f2c 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 14, "id": "c4f10172", "metadata": {}, "outputs": [], @@ -48,11 +48,8 @@ "products =[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", "\n", "inventory = {}\n", - "inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n", - "inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n", - "inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n", - "inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n", - "inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))\n", + "for product in products:\n", + " inventory[product] = int(input(f\"Introduce la cantidad de {product}: \"))\n", "\n", "customer_orders =set()\n", "\n", @@ -63,34 +60,9 @@ " add_another = input(\"Desea seguir añadiendo?\").lower()\n", "\n", "\n", - "for product in inventory:\n", - " inventory[product] -= 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "e10856f8", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "t-shirt: 9\n", - "mug: 8\n", - "hat: 9\n", - "book: 4\n", - "keychain: 5\n" - ] - } - ], - "source": [ - "print (f\"t-shirt: {inventory[\"t-shirt\"]}\")\n", - "print (f\"mug: {inventory[\"mug\"]}\")\n", - "print (f\"hat: {inventory[\"hat\"]}\") \n", - "print (f\"book: {inventory[\"book\"]}\") \n", - "print (f\"keychain: {inventory[\"keychain\"]}\")" + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1" ] } ],