From 3d49a87b55bc94edcf82b04d25ac6641b7fb5e84 Mon Sep 17 00:00:00 2001 From: Juan Boberg Aguirre Date: Tue, 14 Apr 2026 16:40:09 +0200 Subject: [PATCH 1/4] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 116 +++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..ec7742a 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,123 @@ "\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": "cd890423", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "inventory = {}\n", + "\n", + "# Paso 3\n", + "\n", + "\n", + "cantidad_tshirt = int(input(\"¿Cuánt@s t-shirt hay en inventario? \"))\n", + "cantidad_mug = int(input(\"¿Cuánt@s mug hay en inventario? \"))\n", + "cantidad_hat = int(input(\"¿Cuánt@s hat hay en inventario? \"))\n", + "cantidad_book = int(input(\"¿Cuánt@s book hay en inventario? \"))\n", + "cantidad_keychain = int(input(\"¿Cuánt@s keychain hay en inventario? \"))\n", + "\n", + "inventory[\"t-shirt\"] = cantidad_tshirt\n", + "inventory[\"mug\"] = cantidad_mug\n", + "inventory[\"hat\"] = cantidad_hat\n", + "inventory[\"book\"] = cantidad_book\n", + "inventory[\"keychain\"] = cantidad_keychain\n", + "\n", + "# Paso 4\n", + "customer_orders = set()\n", + "\n", + "# Paso 5\n", + "producto1 = input(\"Introduce el primer producto que desea pedir: \")\n", + "producto2 = input(\"Introduce el segundo producto que desea pedir: \")\n", + "producto3 = input(\"Introduce el tercer producto que desea pedir: \")\n", + "\n", + "customer_orders.add(producto1)\n", + "customer_orders.add(producto2)\n", + "customer_orders.add(producto3)\n", + "\n", + "# Paso 6\n", + "print(\"Productos pedidos:\")\n", + "for producto in customer_orders:\n", + " print(producto)\n", + "\n", + "# Paso 7: Calcular las estadísticas del pedido\n", + "total_products_ordered = len(customer_orders) # Total de productos pedidos\n", + "total_available_products = len(products) # Total de productos disponibles\n", + "percentage_ordered = (total_products_ordered / total_available_products) * 100\n", + "order_status = (total_products_ordered, percentage_ordered) # Tupla con las estadísticas\n", + "\n", + "# Paso 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Paso 9\n", + "if \"t-shirt\" in customer_orders:\n", + " inventory[\"t-shirt\"] -= 1\n", + "if \"mug\" in customer_orders:\n", + " inventory[\"mug\"] -= 1\n", + "if \"hat\" in customer_orders:\n", + " inventory[\"hat\"] -= 1\n", + "if \"book\" in customer_orders:\n", + " inventory[\"book\"] -= 1\n", + "if \"keychain\" in customer_orders:\n", + " inventory[\"keychain\"] -= 1\n", + "\n", + "# Paso 10\n", + "print(\"Inventario actualizado:\")\n", + "print(\"t-shirt:\", inventory[\"t-shirt\"])\n", + "print(\"mug:\", inventory[\"mug\"])\n", + "print(\"hat:\", inventory[\"hat\"])\n", + "print(\"book:\", inventory[\"book\"])\n", + "print(\"keychain:\", inventory[\"keychain\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "072c86a9", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " cantidad = int(input(f\"¿Cuánt@s {product} hay en inventario? \"))\n", + " inventory[product] = cantidad\n", + "\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " producto = input(\"Introduce el producto que desea pedir: \")\n", + " customer_orders.add(producto)\n", + "\n", + " otro = input(\"¿Quieres añadir otro producto? (yes/no): \").lower()\n", + "\n", + " if otro == \"no\":\n", + " break\n", + "\n", + "#Paso 3\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +167,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4, From e1b13a132ff895a8d488a7b2af3caaa4be54fed5 Mon Sep 17 00:00:00 2001 From: Juan Boberg Aguirre Date: Tue, 14 Apr 2026 16:43:00 +0200 Subject: [PATCH 2/4] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index ec7742a..86437e1 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -117,10 +117,22 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "id": "072c86a9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: ''", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 8\u001b[39m\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# Paso 2\u001b[39;00m\n\u001b[32m 5\u001b[39m inventory = {}\n\u001b[32m 6\u001b[39m \n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;28;01min\u001b[39;00m products:\n\u001b[32m----> \u001b[39m\u001b[32m8\u001b[39m cantidad = int(input(f\"¿Cuánt@s {product} hay en inventario? \"))\n\u001b[32m 9\u001b[39m inventory[product] = cantidad\n\u001b[32m 10\u001b[39m \n\u001b[32m 11\u001b[39m \n", + "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" + ] + } + ], "source": [ "# Paso 1\n", "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", @@ -147,7 +159,8 @@ "#Paso 3\n", "\n", "for product in customer_orders:\n", - " inventory[product] -= 1" + " inventory[product] -= 1\n", + " " ] } ], From 08d2e162dee6fa13391cde5d7cae09b4d4bd4ad3 Mon Sep 17 00:00:00 2001 From: Juan Boberg Aguirre Date: Tue, 14 Apr 2026 23:24:36 +0200 Subject: [PATCH 3/4] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 42 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 86437e1..ebf1594 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -117,50 +117,46 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "072c86a9", "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "invalid literal for int() with base 10: ''", - "output_type": "error", - "traceback": [ - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", - "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 8\u001b[39m\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# Paso 2\u001b[39;00m\n\u001b[32m 5\u001b[39m inventory = {}\n\u001b[32m 6\u001b[39m \n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;28;01min\u001b[39;00m products:\n\u001b[32m----> \u001b[39m\u001b[32m8\u001b[39m cantidad = int(input(f\"¿Cuánt@s {product} hay en inventario? \"))\n\u001b[32m 9\u001b[39m inventory[product] = cantidad\n\u001b[32m 10\u001b[39m \n\u001b[32m 11\u001b[39m \n", - "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt'}\n", + "{'t-shirt': 9, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n" ] } ], "source": [ - "# Paso 1\n", "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "\n", - "# Paso 2\n", "inventory = {}\n", "\n", "for product in products:\n", - " cantidad = int(input(f\"¿Cuánt@s {product} hay en inventario? \"))\n", - " inventory[product] = cantidad\n", - "\n", + " inventory[product] = int(input(f\"Stock de {product}: \"))\n", "\n", "customer_orders = set()\n", "\n", "while True:\n", - " producto = input(\"Introduce el producto que desea pedir: \")\n", - " customer_orders.add(producto)\n", + " product = input(\"Producto que quiere el cliente: \").lower()\n", "\n", - " otro = input(\"¿Quieres añadir otro producto? (yes/no): \").lower()\n", + " if product in inventory:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Producto no válido.\")\n", "\n", - " if otro == \"no\":\n", + " more = input(\"¿Añadir otro? (yes/no): \").lower()\n", + " if more == \"no\":\n", " break\n", "\n", - "#Paso 3\n", - "\n", "for product in customer_orders:\n", - " inventory[product] -= 1\n", - " " + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "\n", + "print(customer_orders)\n", + "print(inventory)" ] } ], From 6db7074932903ec726e590070ae07b9a57681853 Mon Sep 17 00:00:00 2001 From: Juan Boberg Aguirre Date: Wed, 15 Apr 2026 11:03:24 +0200 Subject: [PATCH 4/4] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 77 ----------------------------------- 1 file changed, 77 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index ebf1594..283050f 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -38,83 +38,6 @@ "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": "cd890423", - "metadata": {}, - "outputs": [], - "source": [ - "# Paso 1\n", - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "\n", - "# Paso 2\n", - "inventory = {}\n", - "\n", - "# Paso 3\n", - "\n", - "\n", - "cantidad_tshirt = int(input(\"¿Cuánt@s t-shirt hay en inventario? \"))\n", - "cantidad_mug = int(input(\"¿Cuánt@s mug hay en inventario? \"))\n", - "cantidad_hat = int(input(\"¿Cuánt@s hat hay en inventario? \"))\n", - "cantidad_book = int(input(\"¿Cuánt@s book hay en inventario? \"))\n", - "cantidad_keychain = int(input(\"¿Cuánt@s keychain hay en inventario? \"))\n", - "\n", - "inventory[\"t-shirt\"] = cantidad_tshirt\n", - "inventory[\"mug\"] = cantidad_mug\n", - "inventory[\"hat\"] = cantidad_hat\n", - "inventory[\"book\"] = cantidad_book\n", - "inventory[\"keychain\"] = cantidad_keychain\n", - "\n", - "# Paso 4\n", - "customer_orders = set()\n", - "\n", - "# Paso 5\n", - "producto1 = input(\"Introduce el primer producto que desea pedir: \")\n", - "producto2 = input(\"Introduce el segundo producto que desea pedir: \")\n", - "producto3 = input(\"Introduce el tercer producto que desea pedir: \")\n", - "\n", - "customer_orders.add(producto1)\n", - "customer_orders.add(producto2)\n", - "customer_orders.add(producto3)\n", - "\n", - "# Paso 6\n", - "print(\"Productos pedidos:\")\n", - "for producto in customer_orders:\n", - " print(producto)\n", - "\n", - "# Paso 7: Calcular las estadísticas del pedido\n", - "total_products_ordered = len(customer_orders) # Total de productos pedidos\n", - "total_available_products = len(products) # Total de productos disponibles\n", - "percentage_ordered = (total_products_ordered / total_available_products) * 100\n", - "order_status = (total_products_ordered, percentage_ordered) # Tupla con las estadísticas\n", - "\n", - "# Paso 8\n", - "print(\"Order Statistics:\")\n", - "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", - "\n", - "# Paso 9\n", - "if \"t-shirt\" in customer_orders:\n", - " inventory[\"t-shirt\"] -= 1\n", - "if \"mug\" in customer_orders:\n", - " inventory[\"mug\"] -= 1\n", - "if \"hat\" in customer_orders:\n", - " inventory[\"hat\"] -= 1\n", - "if \"book\" in customer_orders:\n", - " inventory[\"book\"] -= 1\n", - "if \"keychain\" in customer_orders:\n", - " inventory[\"keychain\"] -= 1\n", - "\n", - "# Paso 10\n", - "print(\"Inventario actualizado:\")\n", - "print(\"t-shirt:\", inventory[\"t-shirt\"])\n", - "print(\"mug:\", inventory[\"mug\"])\n", - "print(\"hat:\", inventory[\"hat\"])\n", - "print(\"book:\", inventory[\"book\"])\n", - "print(\"keychain:\", inventory[\"keychain\"])" - ] - }, { "cell_type": "code", "execution_count": 1,