From 01d2eff52a3613f5024d89ee2eb6b96f26fb47c7 Mon Sep 17 00:00:00 2001 From: aroa Date: Tue, 21 Jul 2026 09:20:34 +0200 Subject: [PATCH 1/2] Solved lab --- lab-python-data-structures.ipynb | 226 ++++++++++++++++++++++++------- 1 file changed, 180 insertions(+), 46 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..18d39459 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -2,75 +2,209 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ - "# Lab | Data Structures " + "# Lab | Data Structures\n", + "\n", + "## Exercise: Managing Customer Orders\n", + "\n", + "Practicamos listas, diccionarios, sets y tuplas resolviendo un pequeño sistema de pedidos." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Exercise: Managing Customer Orders\n", - "\n", - "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "**1.** Define una lista llamada `products` con: 't-shirt', 'mug', 'hat', 'book', 'keychain'.\n", "\n", - "2. Create an empty dictionary called `inventory`.\n", - "\n", - "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "4. Create an empty set called `customer_orders`.\n", - "\n", - "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", - "\n", - "6. Print the products in the `customer_orders` set.\n", - "\n", - "7. Calculate the following order statistics:\n", - " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", - " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - " \n", - " Store these statistics in a tuple called `order_status`.\n", + "*Lista → colección ordenada que recorreremos en secuencia.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**2.** Crea un diccionario vacío llamado `inventory`.\n", "\n", - "8. Print the order statistics using the following format:\n", - " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % \n", - " ```\n", + "*Dict → asocia cada producto (clave) con su cantidad (valor).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**3.** Pide al usuario la cantidad disponible de cada producto y guárdala en `inventory`.\n", "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "*`input()` devuelve string → lo convertimos con `int()`.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**4.** Crea un set vacío llamado `customer_orders`.\n", "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "*Set → los pedidos no se repiten; los duplicados se descartan solos.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**5.** Pide al usuario el nombre de tres productos que el cliente quiere pedir y añádelos a `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for _ in range(3):\n", + " order = input(\"Enter the name of a product the customer wants to order: \")\n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**6.** Imprime los productos del set `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Products in customer_orders:\", customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**7.** Calcula las estadísticas del pedido y guárdalas en una tupla llamada `order_status`:\n", + "- Total de productos pedidos\n", + "- Porcentaje de productos pedidos (sobre el total de productos disponibles)\n", "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + "*Tupla → agrupa datos que no van a cambiar (una \"foto\" del estado).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**8.** Imprime las estadísticas del pedido con el formato indicado." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**9.** Actualiza el inventario restando 1 a la cantidad de cada producto pedido." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**10.** Imprime el inventario actualizado, mostrando la cantidad de cada producto en líneas separadas." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 } From b0b8652917a7d65f81f8521623cfe2b5152b712c Mon Sep 17 00:00:00 2001 From: aroa Date: Wed, 22 Jul 2026 10:49:08 +0200 Subject: [PATCH 2/2] Standardize lab instructions to official English text --- lab-python-data-structures.ipynb | 78 +++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 18d39459..133a8cef 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -4,20 +4,56 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Lab | Data Structures\n", - "\n", + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "## Exercise: Managing Customer Orders\n", "\n", - "Practicamos listas, diccionarios, sets y tuplas resolviendo un pequeño sistema de pedidos." + "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "2. Create an empty dictionary called `inventory`.\n", + "\n", + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", + "\n", + "4. Create an empty set called `customer_orders`.\n", + "\n", + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", + "\n", + "6. Print the products in the `customer_orders` set.\n", + "\n", + "7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + " \n", + " Store these statistics in a tuple called `order_status`.\n", + "\n", + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\n", + "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "**1.** Define una lista llamada `products` con: 't-shirt', 'mug', 'hat', 'book', 'keychain'.\n", - "\n", - "*Lista → colección ordenada que recorreremos en secuencia.*" + "**1.** `products` list." ] }, { @@ -33,9 +69,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**2.** Crea un diccionario vacío llamado `inventory`.\n", - "\n", - "*Dict → asocia cada producto (clave) con su cantidad (valor).*" + "**2.** Empty `inventory` dictionary." ] }, { @@ -51,9 +85,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**3.** Pide al usuario la cantidad disponible de cada producto y guárdala en `inventory`.\n", - "\n", - "*`input()` devuelve string → lo convertimos con `int()`.*" + "**3.** Ask for the quantity of each product and store it in `inventory`." ] }, { @@ -71,9 +103,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**4.** Crea un set vacío llamado `customer_orders`.\n", - "\n", - "*Set → los pedidos no se repiten; los duplicados se descartan solos.*" + "**4.** Empty `customer_orders` set." ] }, { @@ -89,7 +119,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**5.** Pide al usuario el nombre de tres productos que el cliente quiere pedir y añádelos a `customer_orders`." + "**5.** Ask for three products the customer wants to order and add them to `customer_orders`." ] }, { @@ -107,7 +137,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**6.** Imprime los productos del set `customer_orders`." + "**6.** Print the products in `customer_orders`." ] }, { @@ -123,11 +153,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**7.** Calcula las estadísticas del pedido y guárdalas en una tupla llamada `order_status`:\n", - "- Total de productos pedidos\n", - "- Porcentaje de productos pedidos (sobre el total de productos disponibles)\n", - "\n", - "*Tupla → agrupa datos que no van a cambiar (una \"foto\" del estado).*" + "**7.** Order statistics stored in the `order_status` tuple." ] }, { @@ -145,7 +171,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**8.** Imprime las estadísticas del pedido con el formato indicado." + "**8.** Print the order statistics." ] }, { @@ -163,7 +189,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**9.** Actualiza el inventario restando 1 a la cantidad de cada producto pedido." + "**9.** Update the inventory by subtracting 1 from each ordered product." ] }, { @@ -180,7 +206,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**10.** Imprime el inventario actualizado, mostrando la cantidad de cada producto en líneas separadas." + "**10.** Print the updated inventory." ] }, { @@ -202,7 +228,7 @@ }, "language_info": { "name": "python", - "version": "3.11" + "version": "3.x" } }, "nbformat": 4,