From 84876cd689e6a3489a42ce2037aaaafa62b58c8c Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Mon, 13 Apr 2026 22:52:22 +0200 Subject: [PATCH 1/9] Update lab-python-data-structures.ipynb Prueba de entrega --- lab-python-data-structures.ipynb | 275 ++++++++++++++++++++++++++++++- 1 file changed, 273 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..94997409 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,282 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "Products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory[\"T-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory[\"Mug\"] = input(\"Add the inventory for mug itmes, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory[\"Hat\"] = input(\"Add the inventory for hat itmes, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory[\"Book\"] = input(\"Add the inventory for book itmes, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "Inventory[\"Keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(3):\n", + " choice =input(f\"Write the name of the product {i+1}: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You choose: Book\n", + "\n", + "Final order: {'Book'}\n" + ] + } + ], + "source": [ + "customer_orders.add( choice)\n", + "print(f\"You choose: {choice}\")\n", + "print(\"\\nFinal order:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Your order:\n", + " Book\n" + ] + } + ], + "source": [ + "print(\"\\nYour order:\")\n", + "for products in customer_orders:\n", + " print(f\" {products}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total number of product orders: 1\n" + ] + } + ], + "source": [ + "total_products = len(customer_orders)\n", + "print(f\"total number of product orders: {total_products}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "total_inventory = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "total_orders = len(customer_orders)\n", + "percentage = (total_orders / total_inventory)* 100" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_orders, percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total orders: 1\n", + "inventory percentage: 20.0%\n" + ] + } + ], + "source": [ + "print(f\"total orders: {order_status[0]}\")\n", + "print(f\"inventory percentage: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.0%\n" + ] + } + ], + "source": [ + "print(\"\\nOrder Statistics\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {\n", + " \"t-shirt\": 10,\n", + " \"hat\": 5,\n", + " \"book\": 8,\n", + " \"mug\": 12\n", + "} " + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product Book not found in inventory.\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " print(f\"Inventory updated: {product} now has {inventory[product]} units.\")\n", + " else:\n", + " print(f\"Product {product} not found in inventory.\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Updated Inventory ---\n", + "Product: t-shirt | Remaining: 10\n", + "Product: hat | Remaining: 5\n", + "Product: book | Remaining: 8\n", + "Product: mug | Remaining: 12\n" + ] + } + ], + "source": [ + "print(\"\\n--- Updated Inventory ---\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"Product: {product} | Remaining: {quantity}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -68,7 +339,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4, From bddd554c647268581f3a5e8d7715c37465b1d48e Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 13:39:58 +0200 Subject: [PATCH 2/9] Update lab-python-data-structures.ipynb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Actualización errores corregidos --- lab-python-data-structures.ipynb | 144 +++++++++++++++++++------------ 1 file changed, 89 insertions(+), 55 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 94997409..6a0a7c9b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -71,52 +71,52 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "Inventory[\"T-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" + "Inventory[\"t-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "Inventory[\"Mug\"] = input(\"Add the inventory for mug itmes, please: \")" + "Inventory[\"mug\"] = input(\"Add the inventory for mug itmes, please: \")" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "Inventory[\"Hat\"] = input(\"Add the inventory for hat itmes, please: \")" + "Inventory[\"hat\"] = input(\"Add the inventory for hat itmes, please: \")" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "Inventory[\"Book\"] = input(\"Add the inventory for book itmes, please: \")" + "Inventory[\"book\"] = input(\"Add the inventory for book itmes, please: \")" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "Inventory[\"Keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" + "Inventory[\"keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -124,27 +124,27 @@ ] }, { - "cell_type": "code", - "execution_count": 52, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ "for i in range(3):\n", - " choice =input(f\"Write the name of the product {i+1}: \")" + " choice =input(f\"Write the name of the product {i+1}: \").lower()\n", + " customer_orders.add(choice)\n", + "print(\"\\nFinal order:\", customer_orders)" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "You choose: Book\n", + "You choose: book\n", "\n", - "Final order: {'Book'}\n" + "Final order: {'book'}\n" ] } ], @@ -156,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -165,7 +165,9 @@ "text": [ "\n", "Your order:\n", - " Book\n" + " hat\n", + " mug\n", + " book\n" ] } ], @@ -177,14 +179,14 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "total number of product orders: 1\n" + "total number of product orders: 3\n" ] } ], @@ -195,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -204,45 +206,50 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "total_orders = len(customer_orders)\n", - "percentage = (total_orders / total_inventory)* 100" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [], - "source": [ + "total_inventory_items = len(products) # Son 5 productos en total\n", + "percentage = (total_orders / total_inventory_items) * 100\n", "order_status = (total_orders, percentage)" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "total orders: 1\n", - "inventory percentage: 20.0%\n" + "\n", + "Order Statistics\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 75.0%\n" ] } ], "source": [ - "print(f\"total orders: {order_status[0]}\")\n", - "print(f\"inventory percentage: {order_status[1]}%\")" + "print(\"\\nOrder Statistics\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -250,21 +257,46 @@ "output_type": "stream", "text": [ "\n", - "Order Statistics\n", - "Total Products Ordered: 1\n", - "Percentage of Products Ordered: 20.0%\n" + " Updating all inventory items (restando 1)\n" ] } ], "source": [ - "print(\"\\nOrder Statistics\")\n", - "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + "print(\"\\n Updating all inventory items (restando 1)\")\n", + "for product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders Optimized\n", + "\n", + "In the last lab, you were starting an online store that sells various products. To ensure smooth operations, you developed a program that manages customer orders and inventory.\n", + "\n", + "You did so without using flow control. Let's go a step further and improve this code.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Look at your code from the lab data structures, and improve repeated code with loops.\n", + "\n", + "2. Instead of asking the user to input the name of three products that a customer wants to order, do the following:\n", + " \n", + " a. Prompt the user to enter the name of a product that a customer wants to order.\n", + " \n", + " b. Add the product name to the \"customer_orders\" set.\n", + " \n", + " c. Ask the user if they want to add another product (yes/no).\n", + " \n", + " d. Continue the loop until the user does not want to add another product.\n", + "\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": 66, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -278,14 +310,16 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Product Book not found in inventory.\n" + "Inventory updated: hat now has 4 units.\n", + "Inventory updated: mug now has 11 units.\n", + "Inventory updated: book now has 7 units.\n" ] } ], @@ -300,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -310,9 +344,9 @@ "\n", "--- Updated Inventory ---\n", "Product: t-shirt | Remaining: 10\n", - "Product: hat | Remaining: 5\n", - "Product: book | Remaining: 8\n", - "Product: mug | Remaining: 12\n" + "Product: hat | Remaining: 4\n", + "Product: book | Remaining: 7\n", + "Product: mug | Remaining: 11\n" ] } ], @@ -325,7 +359,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, From f1e5fad16b667dca8a7e2cb04b4177d05ad741eb Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 13:55:06 +0200 Subject: [PATCH 3/9] Update lab-python-data-structures.ipynb Correcion errores y mejoras --- lab-python-data-structures.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 6a0a7c9b..4996c963 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -296,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ From 4f529cfeb5feb4895a6966bdaf5dbda67932d309 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 14:09:21 +0200 Subject: [PATCH 4/9] =?UTF-8?q?=C3=9Altimo=20cambio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab-python-data-structures.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 4996c963..814c59a0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -355,6 +355,15 @@ "for product, quantity in inventory.items():\n", " print(f\"Product: {product} | Remaining: {quantity}\")\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Último cambio." + ] } ], "metadata": { From 99b6d680e27bff947dd4066bfdf444c2eec9eb39 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 17:41:46 +0200 Subject: [PATCH 5/9] Update lab-python-data-structures.ipynb Fin de cambios --- lab-python-data-structures.ipynb | 96 +++++++++++++++++++------------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 814c59a0..b63cfc0a 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -51,22 +51,13 @@ "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "Products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]" - ] - }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "Inventory = {}" + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]" ] }, { @@ -75,7 +66,7 @@ "metadata": {}, "outputs": [], "source": [ - "Inventory[\"t-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" + "inventory = {}" ] }, { @@ -84,7 +75,7 @@ "metadata": {}, "outputs": [], "source": [ - "Inventory[\"mug\"] = input(\"Add the inventory for mug itmes, please: \")" + "inventory[\"t-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" ] }, { @@ -93,7 +84,7 @@ "metadata": {}, "outputs": [], "source": [ - "Inventory[\"hat\"] = input(\"Add the inventory for hat itmes, please: \")" + "inventory[\"mug\"] = input(\"Add the inventory for mug items, please: \")" ] }, { @@ -102,7 +93,7 @@ "metadata": {}, "outputs": [], "source": [ - "Inventory[\"book\"] = input(\"Add the inventory for book itmes, please: \")" + "inventory[\"hat\"] = input(\"Add the inventory for hat itmes, please: \")" ] }, { @@ -111,7 +102,7 @@ "metadata": {}, "outputs": [], "source": [ - "Inventory[\"keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" + "inventory[\"book\"] = input(\"Add the inventory for book itmes, please: \")" ] }, { @@ -119,6 +110,15 @@ "execution_count": 8, "metadata": {}, "outputs": [], + "source": [ + "inventory[\"keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], "source": [ "customer_orders = set()" ] @@ -135,28 +135,41 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(3):\n", + " choice = input(f\"Write the name of the product {i+1}: \")\n", + " customer_orders.add(choice)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "You choose: book\n", "\n", - "Final order: {'book'}\n" + "Your order:\n", + "- mug\n", + "- hat\n", + "- book\n" ] } ], "source": [ - "customer_orders.add( choice)\n", - "print(f\"You choose: {choice}\")\n", - "print(\"\\nFinal order:\", customer_orders)" + "print(\"\\nYour order:\")\n", + "for products in customer_orders:\n", + " print(f\"- {products}\")\n" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -165,39 +178,40 @@ "text": [ "\n", "Your order:\n", - " hat\n", - " mug\n", - " book\n" + "- mug\n", + "- hat\n", + "- book\n" ] } ], "source": [ "print(\"\\nYour order:\")\n", "for products in customer_orders:\n", - " print(f\" {products}\")\n" + " print(f\"- {products}\")\n" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "total number of product orders: 3\n" + "\n", + "Total number of product orders: 3\n" ] } ], "source": [ "total_products = len(customer_orders)\n", - "print(f\"total number of product orders: {total_products}\")" + "print(f\"\\nTotal number of product orders: {total_products}\")" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -206,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -218,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -240,16 +254,18 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "inventory = {}" + "inventory = {}\n", + "for product in inventory:\n", + " inventory[product]-=1" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -296,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -310,15 +326,15 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Inventory updated: hat now has 4 units.\n", "Inventory updated: mug now has 11 units.\n", + "Inventory updated: hat now has 4 units.\n", "Inventory updated: book now has 7 units.\n" ] } @@ -334,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -362,7 +378,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Último cambio." + "# Último cambio.Ahora si." ] } ], From f3db27f53c9a96f7869d906a1bb9ed65d2d73623 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Tue, 21 Apr 2026 11:35:13 +0200 Subject: [PATCH 6/9] Update lab-python-data-structures.ipynb Nuevas respuestas --- lab-python-data-structures.ipynb | 196 ++++++------------------------- 1 file changed, 39 insertions(+), 157 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index b63cfc0a..46fec2bd 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -71,52 +71,18 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "inventory[\"t-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "inventory[\"mug\"] = input(\"Add the inventory for mug items, please: \")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "inventory[\"hat\"] = input(\"Add the inventory for hat itmes, please: \")" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "inventory[\"book\"] = input(\"Add the inventory for book itmes, please: \")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "inventory[\"keychain\"] = input(\"Add the inventory for keychain itmes, please: \")" + "for product in products:\n", + " quantity = int(input(f\"Add the inventory for {product}, please: \"))\n", + " inventory[product] = quantity" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -135,41 +101,25 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "for i in range(3):\n", - " choice = input(f\"Write the name of the product {i+1}: \")\n", - " customer_orders.add(choice)" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Your order:\n", - "- mug\n", - "- hat\n", - "- book\n" - ] - } - ], - "source": [ - "print(\"\\nYour order:\")\n", - "for products in customer_orders:\n", - " print(f\"- {products}\")\n" + "while True:\n", + " order = input(\"Enter the name of a product to order: \").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(f\"'{order}' is not a valid product. Please choose from: {products}\")\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break " ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -180,59 +130,31 @@ "Your order:\n", "- mug\n", "- hat\n", - "- book\n" + "- t-shirt\n" ] } ], "source": [ "print(\"\\nYour order:\")\n", "for products in customer_orders:\n", - " print(f\"- {products}\")\n" + " print(f\"- {products}\")" ] }, { "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Total number of product orders: 3\n" - ] - } - ], - "source": [ - "total_products = len(customer_orders)\n", - "print(f\"\\nTotal number of product orders: {total_products}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "total_inventory = 5" - ] - }, - { - "cell_type": "code", - "execution_count": 34, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "total_orders = len(customer_orders)\n", - "total_inventory_items = len(products) # Son 5 productos en total\n", - "percentage = (total_orders / total_inventory_items) * 100\n", + "total_products_available = len(products)\n", + "percentage = (total_orders / total_products_available) * 100\n", "order_status = (total_orders, percentage)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -240,49 +162,18 @@ "output_type": "stream", "text": [ "\n", - "Order Statistics\n", + "Order Statistics:\n", "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 75.0%\n" + "Percentage of Products Ordered: 42.857142857142854%\n" ] } ], "source": [ - "print(\"\\nOrder Statistics\")\n", + "print(\"\\nOrder Statistics:\")\n", "print(f\"Total Products Ordered: {order_status[0]}\")\n", "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" ] }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "inventory = {}\n", - "for product in inventory:\n", - " inventory[product]-=1" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - " Updating all inventory items (restando 1)\n" - ] - } - ], - "source": [ - "print(\"\\n Updating all inventory items (restando 1)\")\n", - "for product in inventory:\n", - " inventory[product] -= 1" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -312,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -326,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -335,7 +226,7 @@ "text": [ "Inventory updated: mug now has 11 units.\n", "Inventory updated: hat now has 4 units.\n", - "Inventory updated: book now has 7 units.\n" + "Inventory updated: t-shirt now has 9 units.\n" ] } ], @@ -350,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -359,32 +250,23 @@ "text": [ "\n", "--- Updated Inventory ---\n", - "Product: t-shirt | Remaining: 10\n", - "Product: hat | Remaining: 4\n", - "Product: book | Remaining: 7\n", - "Product: mug | Remaining: 11\n" + "Product: t-shirt : 9\n", + "Product: hat : 4\n", + "Product: book : 8\n", + "Product: mug : 11\n" ] } ], "source": [ "print(\"\\n--- Updated Inventory ---\")\n", "for product, quantity in inventory.items():\n", - " print(f\"Product: {product} | Remaining: {quantity}\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Último cambio.Ahora si." + " print(f\"Product: {product} : {quantity}\")\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -398,7 +280,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.14.4" + "version": "3.13.9" } }, "nbformat": 4, From 796ccc41b753e07d380a230dc1f18416386583eb Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Tue, 21 Apr 2026 11:51:14 +0200 Subject: [PATCH 7/9] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 46fec2bd..6a5ad281 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -262,6 +262,15 @@ "for product, quantity in inventory.items():\n", " print(f\"Product: {product} : {quantity}\")\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Ultimas soluciones a respuesta de correción." + ] } ], "metadata": { From 22284f2ceb7ce432ce09bc0b74646def7ba6ca37 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Sun, 26 Apr 2026 19:47:26 +0200 Subject: [PATCH 8/9] Update lab-python-data-structures.ipynb Ultimo cambio de verdad --- lab-python-data-structures.ipynb | 218 ++++++------------------------- 1 file changed, 40 insertions(+), 178 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 6a5ad281..5fbe46a2 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -51,129 +51,6 @@ "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "inventory = {}" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "for product in products:\n", - " quantity = int(input(f\"Add the inventory for {product}, please: \"))\n", - " inventory[product] = quantity" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "customer_orders = set()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "for i in range(3):\n", - " choice =input(f\"Write the name of the product {i+1}: \").lower()\n", - " customer_orders.add(choice)\n", - "print(\"\\nFinal order:\", customer_orders)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "while True:\n", - " order = input(\"Enter the name of a product to order: \").strip().lower()\n", - " if order in products:\n", - " customer_orders.add(order)\n", - " else:\n", - " print(f\"'{order}' is not a valid product. Please choose from: {products}\")\n", - " \n", - " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", - " if another != \"yes\":\n", - " break " - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Your order:\n", - "- mug\n", - "- hat\n", - "- t-shirt\n" - ] - } - ], - "source": [ - "print(\"\\nYour order:\")\n", - "for products in customer_orders:\n", - " print(f\"- {products}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "total_orders = len(customer_orders)\n", - "total_products_available = len(products)\n", - "percentage = (total_orders / total_products_available) * 100\n", - "order_status = (total_orders, percentage)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Order Statistics:\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 42.857142857142854%\n" - ] - } - ], - "source": [ - "print(\"\\nOrder Statistics:\")\n", - "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -203,64 +80,49 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "inventory = {\n", - " \"t-shirt\": 10,\n", - " \"hat\": 5,\n", - " \"book\": 8,\n", - " \"mug\": 12\n", - "} " - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Inventory updated: mug now has 11 units.\n", - "Inventory updated: hat now has 4 units.\n", - "Inventory updated: t-shirt now has 9 units.\n" - ] - } - ], - "source": [ + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "inventory = {}\n", + "\n", + "# Paso 3\n", + "for product in products:\n", + " inventory[product] = int(input(f\"Introduce la cantidad de {product}: \"))\n", + "\n", + "# Paso 4\n", + "customer_orders = set()\n", + "\n", + "# Paso 5 - Mejorado con while\n", + "answer = \"yes\"\n", + "while answer == \"yes\":\n", + " product = input(\"Introduce el nombre del producto: \")\n", + " customer_orders.add(product)\n", + " answer = input(\"¿Quieres añadir otro producto? (yes/no): \")\n", + " if answer == \"no\":\n", + " break\n", + "\n", + "# Paso 6\n", + "print(customer_orders)\n", + "\n", + "# Paso 7\n", + "total_products_ordered = len(customer_orders)\n", + "percentage = (len(customer_orders) / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage)\n", + "\n", + "# Paso 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage}%\")\n", + "\n", + "# Paso 9 y 10 - Mejorado, solo productos pedidos\n", "for product in customer_orders:\n", - " if product in inventory:\n", - " inventory[product] -= 1\n", - " print(f\"Inventory updated: {product} now has {inventory[product]} units.\")\n", - " else:\n", - " print(f\"Product {product} not found in inventory.\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "--- Updated Inventory ---\n", - "Product: t-shirt : 9\n", - "Product: hat : 4\n", - "Product: book : 8\n", - "Product: mug : 11\n" - ] - } - ], - "source": [ - "print(\"\\n--- Updated Inventory ---\")\n", - "for product, quantity in inventory.items():\n", - " print(f\"Product: {product} : {quantity}\")\n" + " inventory[product] -= 1\n", + " print(f\"Inventario actualizado [{product}]: {inventory[product]}\")" ] }, { @@ -269,7 +131,7 @@ "metadata": {}, "outputs": [], "source": [ - "#Ultimas soluciones a respuesta de correción." + "\n" ] } ], From 68f2893ce3a339b78910b2abdb96fbb16775a62d Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Mon, 27 Apr 2026 12:30:11 +0200 Subject: [PATCH 9/9] Update lab-python-data-structures.ipynb ultima correcion --- lab-python-data-structures.ipynb | 37 ++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5fbe46a2..db78668a 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -80,9 +80,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'keychain', 'mug'}\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n", + "t-shirt: 9\n", + "mug: 7\n", + "hat: 6\n", + "book: 6\n", + "keychain: 4\n" + ] + } + ], "source": [ "# Paso 1\n", "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", @@ -97,14 +113,15 @@ "# Paso 4\n", "customer_orders = set()\n", "\n", - "# Paso 5 - Mejorado con while\n", + "# Paso 5 - Mejorando while\n", "answer = \"yes\"\n", "while answer == \"yes\":\n", " product = input(\"Introduce el nombre del producto: \")\n", - " customer_orders.add(product)\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Producto no válido, inténtalo de nuevo por favor\")\n", " answer = input(\"¿Quieres añadir otro producto? (yes/no): \")\n", - " if answer == \"no\":\n", - " break\n", "\n", "# Paso 6\n", "print(customer_orders)\n", @@ -116,13 +133,15 @@ "\n", "# Paso 8\n", "print(\"Order Statistics:\")\n", - "print(f\"Total Products Ordered: {total_products_ordered}\")\n", - "print(f\"Percentage of Products Ordered: {percentage}%\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n", "\n", "# Paso 9 y 10 - Mejorado, solo productos pedidos\n", "for product in customer_orders:\n", " inventory[product] -= 1\n", - " print(f\"Inventario actualizado [{product}]: {inventory[product]}\")" + "\n", + "for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\")" ] }, {