From 15ef46ba3b74746d1c26bd0faafeab413b7f641e Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 19:36:06 +0200 Subject: [PATCH 1/3] Update lab-python-functions.ipynb respuestas --- lab-python-functions.ipynb | 180 ++++++++++++++++++++++++++++++++++++- 1 file changed, 178 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..3f9110a 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,187 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "b357384e", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory =[]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5cee0b07", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products_list):\n", + " inventory_dict = {}\n", + " print(\"--- Setup Inventory ---\")\n", + " for item in products_list:\n", + " quantity = int(input(f\"Add the inventory for {item} items, please: \"))\n", + " inventory_dict[item] = quantity\n", + " return inventory_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "bdb3f242", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + " another_product = \"yes\"\n", + " print(\"\\n--- Place Your Orders ---\")\n", + " while another_product.lower() in [\"yes\", \"sí\", \"si\"]:\n", + " choice = input(\"Enter the name of the product to order: \")\n", + " customer_orders.add(choice)\n", + " another_product = input(\"Do you want to add another product? (yes/no): \")\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "ff7cdc27", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products_list):\n", + " total_orders = len(customer_orders)\n", + " percentage = (total_orders / len(products_list)) * 100\n", + " return total_orders, percentage" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "ed8253f8", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(\"\\n--- Order Summary ---\")\n", + " print(f\"Total Products Ordered: {total}\")\n", + " print(f\"Percentage of Products Ordered: {percentage:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "a445f51d", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " print(\"\\n--- Processing Inventory Updates ---\")\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " print(f\"Stock updated for: {product}\")\n", + " else:\n", + " print(f\"Note: {product} was not in the catalog.\")\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "4c92bcfd", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"\\n--- Final Updated Inventory ---\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"Product: {product:12} | Stock Remaining: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "dfd872ae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--- Setup Inventory ---\n" + ] + } + ], + "source": [ + "current_inventory = initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "e3acaf0e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Place Your Orders ---\n", + "\n", + "--- Order Summary ---\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "orders = get_customer_orders()\n", + "stats = calculate_order_statistics(orders, products)\n", + "print_order_statistics(stats)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "ff7fad61", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Processing Inventory Updates ---\n", + "Stock updated for: mug\n", + "Stock updated for: t-shirt\n", + "Stock updated for: hat\n", + "\n", + "--- Final Updated Inventory ---\n", + "Product: t-shirt | Stock Remaining: 7\n", + "Product: mug | Stock Remaining: 4\n", + "Product: hat | Stock Remaining: 5\n", + "Product: book | Stock Remaining: 4\n", + "Product: keychain | Stock Remaining: 3\n" + ] + } + ], + "source": [ + "current_inventory = update_inventory(orders, current_inventory)\n", + "print_updated_inventory(current_inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +237,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4, From c6e133d729162e5ff9ba638216cd11362049f544 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Wed, 29 Apr 2026 12:09:22 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Correci=C3=B3n=20de=20errores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab-python-functions.ipynb | 231 +++++++++++-------------------------- 1 file changed, 67 insertions(+), 164 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 3f9110a..6931775 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,184 +46,87 @@ }, { "cell_type": "code", - "execution_count": 24, - "id": "b357384e", - "metadata": {}, - "outputs": [], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "inventory =[]" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "5cee0b07", - "metadata": {}, - "outputs": [], - "source": [ - "def initialize_inventory(products_list):\n", - " inventory_dict = {}\n", - " print(\"--- Setup Inventory ---\")\n", - " for item in products_list:\n", - " quantity = int(input(f\"Add the inventory for {item} items, please: \"))\n", - " inventory_dict[item] = quantity\n", - " return inventory_dict" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "bdb3f242", - "metadata": {}, - "outputs": [], - "source": [ - "def get_customer_orders():\n", - " customer_orders = set()\n", - " another_product = \"yes\"\n", - " print(\"\\n--- Place Your Orders ---\")\n", - " while another_product.lower() in [\"yes\", \"sí\", \"si\"]:\n", - " choice = input(\"Enter the name of the product to order: \")\n", - " customer_orders.add(choice)\n", - " another_product = input(\"Do you want to add another product? (yes/no): \")\n", - " return customer_orders" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "ff7cdc27", - "metadata": {}, - "outputs": [], - "source": [ - "def calculate_order_statistics(customer_orders, products_list):\n", - " total_orders = len(customer_orders)\n", - " percentage = (total_orders / len(products_list)) * 100\n", - " return total_orders, percentage" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "id": "ed8253f8", - "metadata": {}, - "outputs": [], - "source": [ - "def print_order_statistics(order_statistics):\n", - " total, percentage = order_statistics\n", - " print(\"\\n--- Order Summary ---\")\n", - " print(f\"Total Products Ordered: {total}\")\n", - " print(f\"Percentage of Products Ordered: {percentage:.2f}%\")" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "id": "a445f51d", - "metadata": {}, - "outputs": [], - "source": [ - "def update_inventory(customer_orders, inventory):\n", - " print(\"\\n--- Processing Inventory Updates ---\")\n", - " for product in customer_orders:\n", - " if product in inventory:\n", - " inventory[product] -= 1\n", - " print(f\"Stock updated for: {product}\")\n", - " else:\n", - " print(f\"Note: {product} was not in the catalog.\")\n", - " return inventory" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "id": "4c92bcfd", - "metadata": {}, - "outputs": [], - "source": [ - "def print_updated_inventory(inventory):\n", - " print(\"\\n--- Final Updated Inventory ---\")\n", - " for product, quantity in inventory.items():\n", - " print(f\"Product: {product:12} | Stock Remaining: {quantity}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "id": "dfd872ae", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "--- Setup Inventory ---\n" - ] - } - ], - "source": [ - "current_inventory = initialize_inventory(products)" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "e3acaf0e", + "execution_count": 1, + "id": "19e1fe41", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "--- Place Your Orders ---\n", - "\n", - "--- Order Summary ---\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 60.00%\n" + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.0%\n", + "t-shirt: 8\n", + "mug: 7\n", + "hat: 7\n", + "book: 6\n", + "keychain: 5\n" ] } ], "source": [ - "orders = get_customer_orders()\n", - "stats = calculate_order_statistics(orders, products)\n", - "print_order_statistics(stats)" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "ff7fad61", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "--- Processing Inventory Updates ---\n", - "Stock updated for: mug\n", - "Stock updated for: t-shirt\n", - "Stock updated for: hat\n", - "\n", - "--- Final Updated Inventory ---\n", - "Product: t-shirt | Stock Remaining: 7\n", - "Product: mug | Stock Remaining: 4\n", - "Product: hat | Stock Remaining: 5\n", - "Product: book | Stock Remaining: 4\n", - "Product: keychain | Stock Remaining: 3\n" - ] - } - ], - "source": [ - "current_inventory = update_inventory(orders, current_inventory)\n", - "print_updated_inventory(current_inventory)" + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "def initialize_inventory (products):\n", + " inventory = {}\n", + " for product in products:\n", + " inventory[product] = int(input(f\"Introduce la cantidad de {product}: \"))\n", + " return inventory\n", + "\n", + "# Paso 3\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " answer = \"yes\"\n", + " while answer == \"yes\":\n", + " product = input(\"Introduce el nombre del producto: \").strip().lower()\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): \").lower()\n", + " return customer_orders\n", + "\n", + "# Paso 4\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + " return inventory\n", + "\n", + "# Paso 5\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage = (len(customer_orders) / len(products)) * 100\n", + " order_status = (total_products_ordered, percentage)\n", + " return order_status\n", + "\n", + "# Paso 6\n", + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics:\")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]}%\")\n", + "\n", + "#Paso 7\n", + "def print_updated_inventory(inventory):\n", + " for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\")\n", + "\n", + "#Paso 8: Llamadas a la función.\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "print_order_statistics(order_statistics)\n", + "print_updated_inventory(inventory)\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -237,7 +140,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.14.4" + "version": "3.13.9" } }, "nbformat": 4, From 8cfd8afd6835deba3c29b606f711418b776f6195 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Wed, 29 Apr 2026 12:34:30 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Correcci=C3=B3n=20nueva?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab-python-functions.ipynb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 6931775..d44869d 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -55,9 +55,9 @@ "output_type": "stream", "text": [ "Order Statistics:\n", - "Total Products Ordered: 2\n", - "Percentage of Products Ordered: 40.0%\n", - "t-shirt: 8\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.0%\n", + "t-shirt: 9\n", "mug: 7\n", "hat: 7\n", "book: 6\n", @@ -77,7 +77,7 @@ " return inventory\n", "\n", "# Paso 3\n", - "def get_customer_orders():\n", + "def get_customer_orders (products):\n", " customer_orders = set()\n", " answer = \"yes\"\n", " while answer == \"yes\":\n", @@ -92,7 +92,8 @@ "# Paso 4\n", "def update_inventory(customer_orders, inventory):\n", " for product in customer_orders:\n", - " inventory[product] -= 1\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", "\n", " return inventory\n", "\n", @@ -105,18 +106,18 @@ "\n", "# Paso 6\n", "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", " print(\"Order Statistics:\")\n", - " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", - " print(f\"Percentage of Products Ordered: {order_statistics[1]}%\")\n", - "\n", + " print(f\"Total Products Ordered: {total}\")\n", + " print(f\"Percentage of Products Ordered: {percentage}%\")\n", "#Paso 7\n", "def print_updated_inventory(inventory):\n", - " for product in inventory:\n", - " print(f\"{product}: {inventory[product]}\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", "\n", "#Paso 8: Llamadas a la función.\n", "inventory = initialize_inventory(products)\n", - "customer_orders = get_customer_orders()\n", + "customer_orders = get_customer_orders(products)\n", "update_inventory(customer_orders, inventory)\n", "order_statistics = calculate_order_statistics(customer_orders, products)\n", "print_order_statistics(order_statistics)\n",