From 449ffbad508c6bb0c669748fa59f89cbc372e206 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 Oct 2025 15:51:07 +0200 Subject: [PATCH 1/2] Update lab-python-data-structures.ipynb Lab hasta el ejercicio 8 --- lab-python-data-structures.ipynb | 170 ++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..4ca6879f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,177 @@ "\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": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# crear una lista llamada products\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# crear un diccionario vacío llamado inventory\n", + "\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# solicitar la cantidad de cada producto para poner en Inventory, usando los productos de products como keys y las cantidades como values\n", + "\n", + "tshirt_quant = int(input(\"put the number of t-shirts\"))\n", + "mug_quant = int(input(\"put the number of mugs\"))\n", + "hat_quant = int(input(\"put the number of hats\"))\n", + "books_quant = int(input(\"put the number of books\"))\n", + "keychain_quant = int(input(\"put the number of keychains\"))\n", + "\n", + "inventory[products[0]] = tshirt_quant\n", + "inventory[products[1]] = mug_quant\n", + "inventory[products[2]] = hat_quant\n", + "inventory[products[3]] = books_quant\n", + "inventory[products[4]] = keychain_quant\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 85, 'mug': 99, 'hat': 65, 'book': 50, 'keychain': 22}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "# crear un set vacío que sea costumer_orders\n", + "\n", + "costumer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'book', 'keychain'}\n" + ] + } + ], + "source": [ + "# pedir al cliente que seleccione 3 prodcutos de la lista products\n", + "\n", + "costumer_prod = input(\"select a product\")\n", + "\n", + "costumer_orders.add(costumer_prod)\n", + "\n", + "print(costumer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "# calcular el total de productos pedidos y el porcentaje correspondiente sobre la lista total de productos\n", + "\n", + "length = int(len(costumer_orders))\n", + "\n", + "print(length)\n", + "\n", + "porcentaje_pedido = 300 / 5\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "60.0" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "porcentaje_pedido" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "60.0\n" + ] + } + ], + "source": [ + "total_product_ordered = print(length)\n", + "\n", + "percentage_product_ordered = print(porcentaje_pedido)\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +234,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" } }, "nbformat": 4, From 16bd19cfd3fb719a65294eb6c02ad7f15a5e3143 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 Oct 2025 18:58:28 +0200 Subject: [PATCH 2/2] Update lab-python-data-structures.ipynb lab finalizado --- lab-python-data-structures.ipynb | 101 +++++++++++++++++-------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 4ca6879f..dc2534bc 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -64,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -99,16 +99,16 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'t-shirt': 85, 'mug': 99, 'hat': 65, 'book': 50, 'keychain': 22}" + "{'t-shirt': 89, 'mug': 55, 'hat': 63, 'book': 78, 'keychain': 50}" ] }, - "execution_count": 11, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -119,102 +119,113 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# crear un set vacío que sea costumer_orders\n", "\n", - "costumer_orders = set()" + "customer_orders = set()" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'mug', 'book', 'keychain'}\n" + "{'book', 'keychain', 'mug'}\n" ] } ], "source": [ "# pedir al cliente que seleccione 3 prodcutos de la lista products\n", "\n", - "costumer_prod = input(\"select a product\")\n", + "customer_prod_1 = input(\"select a product\")\n", + "customer_prod_2 = input(\"select a product\")\n", + "customer_prod_3 = input(\"select a product\")\n", "\n", - "costumer_orders.add(costumer_prod)\n", + "customer_orders.add(customer_prod_1)\n", + "customer_orders.add(customer_prod_2)\n", + "customer_orders.add(customer_prod_3)\n", "\n", - "print(costumer_orders)" + "print(customer_orders)" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "# calcular el total de productos pedidos y el porcentaje correspondiente sobre la lista total de productos\n", + "\n", + "\n", + "porcentaje_pedido = (len(customer_orders) / len(products)) * 100\n", + "order_status = (len(customer_orders), porcentaje_pedido)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3\n" + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0\n" ] } ], "source": [ - "# calcular el total de productos pedidos y el porcentaje correspondiente sobre la lista total de productos\n", - "\n", - "length = int(len(costumer_orders))\n", - "\n", - "print(length)\n", - "\n", - "porcentaje_pedido = 300 / 5\n", - "\n", - "\n" + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1])" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 32, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "60.0" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "porcentaje_pedido" + "# restar 1 a la cantidad de cada producto en inventory por cada producto en customer_orders\n", + "\n", + "for product_name in inventory:\n", + " # Resta 1 a la cantidad del producto actual\n", + " inventory[product_name] = inventory[product_name] - 1\n", + " " ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3\n", - "60.0\n" + "\n", + "Inventario Actualizado:\n", + "t-shirt: 88\n", + "mug: 54\n", + "hat: 62\n", + "book: 77\n", + "keychain: 49\n" ] } ], "source": [ - "total_product_ordered = print(length)\n", - "\n", - "percentage_product_ordered = print(porcentaje_pedido)\n", - "\n" + "print(\"\\nInventario Actualizado:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" ] } ],