From f1d3d3b1b767f93be15d2979f170c1c50c1d6d99 Mon Sep 17 00:00:00 2001 From: Sergiioblazq Date: Sat, 14 Jun 2025 11:07:02 +0200 Subject: [PATCH 1/2] Add files via upload --- lab-python-error-handling.ipynb | 196 ++++++++++++++++---------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/lab-python-error-handling.ipynb b/lab-python-error-handling.ipynb index f4c6ef6..9d2680b 100644 --- a/lab-python-error-handling.ipynb +++ b/lab-python-error-handling.ipynb @@ -1,98 +1,98 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", - "metadata": {}, - "source": [ - "# Lab | Error Handling" - ] - }, - { - "cell_type": "markdown", - "id": "bc99b386-7508-47a0-bcdb-d969deaf6c8b", - "metadata": {}, - "source": [ - "## Exercise: Error Handling for Managing Customer Orders\n", - "\n", - "The implementation of your code for managing customer orders assumes that the user will always enter a valid input. \n", - "\n", - "For example, we could modify the `initialize_inventory` function to include error handling.\n", - " - If the user enters an invalid quantity (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the quantity for that product.\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid quantity is entered.\n", - "\n", - "```python\n", - "# Step 1: Define the function for initializing the inventory with error handling\n", - "def initialize_inventory(products):\n", - " inventory = {}\n", - " for product in products:\n", - " valid_quantity = False\n", - " while not valid_quantity:\n", - " try:\n", - " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", - " if quantity < 0:\n", - " raise ValueError(\"Invalid quantity! Please enter a non-negative value.\")\n", - " valid_quantity = True\n", - " except ValueError as error:\n", - " print(f\"Error: {error}\")\n", - " inventory[product] = quantity\n", - " return inventory\n", - "\n", - "# Or, in another way:\n", - "\n", - "def initialize_inventory(products):\n", - " inventory = {}\n", - " for product in products:\n", - " valid_input = False\n", - " while not valid_input:\n", - " try:\n", - " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", - " if quantity >= 0:\n", - " inventory[product] = quantity\n", - " valid_input = True\n", - " else:\n", - " print(\"Quantity cannot be negative. Please enter a valid quantity.\")\n", - " except ValueError:\n", - " print(\"Invalid input. Please enter a valid quantity.\")\n", - " return inventory\n", - "```\n", - "\n", - "Let's enhance your code by implementing error handling to handle invalid inputs.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "2. Modify the `calculate_total_price` function to include error handling.\n", - " - If the user enters an invalid price (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the price for that product.\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid price is entered.\n", - "\n", - "3. Modify the `get_customer_orders` function to include error handling.\n", - " - If the user enters an invalid number of orders (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the number of orders.\n", - " - If the user enters an invalid product name (e.g., a product name that is not in the inventory), or that doesn't have stock available, display an error message and ask them to re-enter the product name. *Hint: you will need to pass inventory as a parameter*\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid product name is entered.\n", - "\n", - "4. Test your code by running the program and deliberately entering invalid quantities and product names. Make sure the error handling mechanism works as expected.\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} +{ + "cells": [ + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": {}, + "source": [ + "# Lab | Error Handling" + ] + }, + { + "cell_type": "markdown", + "id": "bc99b386-7508-47a0-bcdb-d969deaf6c8b", + "metadata": {}, + "source": [ + "## Exercise: Error Handling for Managing Customer Orders\n", + "\n", + "The implementation of your code for managing customer orders assumes that the user will always enter a valid input. \n", + "\n", + "For example, we could modify the `initialize_inventory` function to include error handling.\n", + " - If the user enters an invalid quantity (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the quantity for that product.\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid quantity is entered.\n", + "\n", + "```python\n", + "# Step 1: Define the function for initializing the inventory with error handling\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " valid_quantity = False\n", + " while not valid_quantity:\n", + " try:\n", + " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", + " if quantity < 0:\n", + " raise ValueError(\"Invalid quantity! Please enter a non-negative value.\")\n", + " valid_quantity = True\n", + " except ValueError as error:\n", + " print(f\"Error: {error}\")\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "# Or, in another way:\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " valid_input = False\n", + " while not valid_input:\n", + " try:\n", + " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", + " if quantity >= 0:\n", + " inventory[product] = quantity\n", + " valid_input = True\n", + " else:\n", + " print(\"Quantity cannot be negative. Please enter a valid quantity.\")\n", + " except ValueError:\n", + " print(\"Invalid input. Please enter a valid quantity.\")\n", + " return inventory\n", + "```\n", + "\n", + "Let's enhance your code by implementing error handling to handle invalid inputs.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "2. Modify the `calculate_total_price` function to include error handling.\n", + " - If the user enters an invalid price (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the price for that product.\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid price is entered.\n", + "\n", + "3. Modify the `get_customer_orders` function to include error handling.\n", + " - If the user enters an invalid number of orders (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the number of orders.\n", + " - If the user enters an invalid product name (e.g., a product name that is not in the inventory), or that doesn't have stock available, display an error message and ask them to re-enter the product name. *Hint: you will need to pass inventory as a parameter*\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid product name is entered.\n", + "\n", + "4. Test your code by running the program and deliberately entering invalid quantities and product names. Make sure the error handling mechanism works as expected.\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 35a50eed9506124f154d4931455483d4bf3c008e Mon Sep 17 00:00:00 2001 From: Sergiioblazq Date: Sat, 14 Jun 2025 11:15:34 +0200 Subject: [PATCH 2/2] Add files via upload --- lab-python-error-handling.ipynb | 364 +++++++++++++++++++++++--------- 1 file changed, 266 insertions(+), 98 deletions(-) diff --git a/lab-python-error-handling.ipynb b/lab-python-error-handling.ipynb index 9d2680b..45d165f 100644 --- a/lab-python-error-handling.ipynb +++ b/lab-python-error-handling.ipynb @@ -1,98 +1,266 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", - "metadata": {}, - "source": [ - "# Lab | Error Handling" - ] - }, - { - "cell_type": "markdown", - "id": "bc99b386-7508-47a0-bcdb-d969deaf6c8b", - "metadata": {}, - "source": [ - "## Exercise: Error Handling for Managing Customer Orders\n", - "\n", - "The implementation of your code for managing customer orders assumes that the user will always enter a valid input. \n", - "\n", - "For example, we could modify the `initialize_inventory` function to include error handling.\n", - " - If the user enters an invalid quantity (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the quantity for that product.\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid quantity is entered.\n", - "\n", - "```python\n", - "# Step 1: Define the function for initializing the inventory with error handling\n", - "def initialize_inventory(products):\n", - " inventory = {}\n", - " for product in products:\n", - " valid_quantity = False\n", - " while not valid_quantity:\n", - " try:\n", - " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", - " if quantity < 0:\n", - " raise ValueError(\"Invalid quantity! Please enter a non-negative value.\")\n", - " valid_quantity = True\n", - " except ValueError as error:\n", - " print(f\"Error: {error}\")\n", - " inventory[product] = quantity\n", - " return inventory\n", - "\n", - "# Or, in another way:\n", - "\n", - "def initialize_inventory(products):\n", - " inventory = {}\n", - " for product in products:\n", - " valid_input = False\n", - " while not valid_input:\n", - " try:\n", - " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", - " if quantity >= 0:\n", - " inventory[product] = quantity\n", - " valid_input = True\n", - " else:\n", - " print(\"Quantity cannot be negative. Please enter a valid quantity.\")\n", - " except ValueError:\n", - " print(\"Invalid input. Please enter a valid quantity.\")\n", - " return inventory\n", - "```\n", - "\n", - "Let's enhance your code by implementing error handling to handle invalid inputs.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "2. Modify the `calculate_total_price` function to include error handling.\n", - " - If the user enters an invalid price (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the price for that product.\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid price is entered.\n", - "\n", - "3. Modify the `get_customer_orders` function to include error handling.\n", - " - If the user enters an invalid number of orders (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the number of orders.\n", - " - If the user enters an invalid product name (e.g., a product name that is not in the inventory), or that doesn't have stock available, display an error message and ask them to re-enter the product name. *Hint: you will need to pass inventory as a parameter*\n", - " - Use a try-except block to handle the error and continue prompting the user until a valid product name is entered.\n", - "\n", - "4. Test your code by running the program and deliberately entering invalid quantities and product names. Make sure the error handling mechanism works as expected.\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} +{ + "cells": [ + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": {}, + "source": [ + "# Lab | Error Handling" + ] + }, + { + "cell_type": "markdown", + "id": "bc99b386-7508-47a0-bcdb-d969deaf6c8b", + "metadata": {}, + "source": [ + "## Exercise: Error Handling for Managing Customer Orders\n", + "\n", + "The implementation of your code for managing customer orders assumes that the user will always enter a valid input. \n", + "\n", + "For example, we could modify the `initialize_inventory` function to include error handling.\n", + " - If the user enters an invalid quantity (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the quantity for that product.\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid quantity is entered.\n", + "\n", + "```python\n", + "# Step 1: Define the function for initializing the inventory with error handling\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " valid_quantity = False\n", + " while not valid_quantity:\n", + " try:\n", + " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", + " if quantity < 0:\n", + " raise ValueError(\"Invalid quantity! Please enter a non-negative value.\")\n", + " valid_quantity = True\n", + " except ValueError as error:\n", + " print(f\"Error: {error}\")\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "# Or, in another way:\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " valid_input = False\n", + " while not valid_input:\n", + " try:\n", + " quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n", + " if quantity >= 0:\n", + " inventory[product] = quantity\n", + " valid_input = True\n", + " else:\n", + " print(\"Quantity cannot be negative. Please enter a valid quantity.\")\n", + " except ValueError:\n", + " print(\"Invalid input. Please enter a valid quantity.\")\n", + " return inventory\n", + "```\n", + "\n", + "Let's enhance your code by implementing error handling to handle invalid inputs.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "2. Modify the `calculate_total_price` function to include error handling.\n", + " - If the user enters an invalid price (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the price for that product.\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid price is entered.\n", + "\n", + "3. Modify the `get_customer_orders` function to include error handling.\n", + " - If the user enters an invalid number of orders (e.g., a negative value or a non-numeric value), display an error message and ask them to re-enter the number of orders.\n", + " - If the user enters an invalid product name (e.g., a product name that is not in the inventory), or that doesn't have stock available, display an error message and ask them to re-enter the product name. *Hint: you will need to pass inventory as a parameter*\n", + " - Use a try-except block to handle the error and continue prompting the user until a valid product name is entered.\n", + "\n", + "4. Test your code by running the program and deliberately entering invalid quantities and product names. Make sure the error handling mechanism works as expected.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b9f4d63d", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 1: Definir la función para inicializar el inventario con manejo de errores\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " valid_quantity = False\n", + " while not valid_quantity:\n", + " try:\n", + " quantity = int(input(f\"Ingrese la cantidad disponible de {product}: \"))\n", + " if quantity < 0:\n", + " print(\"La cantidad no puede ser negativa. Intente de nuevo.\")\n", + " else:\n", + " inventory[product] = quantity\n", + " valid_quantity = True\n", + " except ValueError:\n", + " print(\"Entrada inválida. Por favor, ingrese un número entero.\")\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "552da3b9", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 2: Modificar la función calculate_total_price para incluir manejo de errores\n", + "\n", + "def calculate_total_price(products):\n", + " prices = {}\n", + " for product in products:\n", + " valid_price = False\n", + " while not valid_price:\n", + " try:\n", + " price = float(input(f\"Enter the price for {product}: \"))\n", + " if price < 0:\n", + " print(\"Price cannot be negative. Please enter a valid price.\")\n", + " else:\n", + " prices[product] = price\n", + " valid_price = True\n", + " except ValueError:\n", + " print(\"Invalid input. Please enter a numeric value for the price.\")\n", + " return prices" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "3ce552b5", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 3: Modificar la función get_customer_orders para incluir manejo de errores\n", + "\n", + "def get_customer_orders(inventory):\n", + " orders = {}\n", + " products = list(inventory.keys())\n", + " # Solicitar el número de pedidos\n", + " while True:\n", + " try:\n", + " num_orders = int(input(\"Ingrese el número de pedidos: \"))\n", + " if num_orders < 0:\n", + " print(\"El número de pedidos no puede ser negativo. Intente de nuevo.\")\n", + " else:\n", + " break\n", + " except ValueError:\n", + " print(\"Entrada inválida. Por favor, ingrese un número entero.\")\n", + "\n", + " for _ in range(num_orders):\n", + " while True:\n", + " product = input(f\"Ingrese el nombre del producto ({', '.join(products)}): \")\n", + " if product not in inventory:\n", + " print(\"Producto no encontrado en el inventario. Intente de nuevo.\")\n", + " elif inventory[product] <= 0:\n", + " print(f\"No hay stock disponible para {product}. Elija otro producto.\")\n", + " else:\n", + " break\n", + " while True:\n", + " try:\n", + " quantity = int(input(f\"Ingrese la cantidad de {product} que desea pedir: \"))\n", + " if quantity < 0:\n", + " print(\"La cantidad no puede ser negativa. Intente de nuevo.\")\n", + " elif quantity > inventory[product]:\n", + " print(f\"Cantidad insuficiente en inventario. Solo hay {inventory[product]} disponibles.\")\n", + " else:\n", + " break\n", + " except ValueError:\n", + " print(\"Entrada inválida. Por favor, ingrese un número entero.\")\n", + " orders[product] = orders.get(product, 0) + quantity\n", + " inventory[product] -= quantity\n", + " return orders" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "3c43c0ac", + "metadata": { + "vscode": { + "languageId": "ruby" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n", + "Producto no encontrado en el inventario. Intente de nuevo.\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "Interrupted by user", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mKeyboardInterrupt\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[32m 10\u001b[39m precios = calculate_total_price(productos)\n\u001b[32m 12\u001b[39m \u001b[38;5;66;03m# Obtener pedidos de clientes con manejo de errores\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m13\u001b[39m pedidos = \u001b[43mget_customer_orders\u001b[49m\u001b[43m(\u001b[49m\u001b[43minventario\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 15\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mInventario final:\u001b[39m\u001b[33m\"\u001b[39m, inventario)\n\u001b[32m 16\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mPrecios:\u001b[39m\u001b[33m\"\u001b[39m, precios)\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[8]\u001b[39m\u001b[32m, line 19\u001b[39m, in \u001b[36mget_customer_orders\u001b[39m\u001b[34m(inventory)\u001b[39m\n\u001b[32m 17\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(num_orders):\n\u001b[32m 18\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m19\u001b[39m product = \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mIngrese el nombre del producto (\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[33;43m'\u001b[39;49m\u001b[33;43m, \u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43mproducts\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m): \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 20\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m product \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m inventory:\n\u001b[32m 21\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mProducto no encontrado en el inventario. Intente de nuevo.\u001b[39m\u001b[33m\"\u001b[39m)\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\sergi\\OneDrive\\Documentos\\IRONHACK\\venv\\Lib\\site-packages\\ipykernel\\kernelbase.py:1282\u001b[39m, in \u001b[36mKernel.raw_input\u001b[39m\u001b[34m(self, prompt)\u001b[39m\n\u001b[32m 1280\u001b[39m msg = \u001b[33m\"\u001b[39m\u001b[33mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1281\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(msg)\n\u001b[32m-> \u001b[39m\u001b[32m1282\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1283\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1284\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mshell\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1285\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mshell\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1286\u001b[39m \u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 1287\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\sergi\\OneDrive\\Documentos\\IRONHACK\\venv\\Lib\\site-packages\\ipykernel\\kernelbase.py:1325\u001b[39m, in \u001b[36mKernel._input_request\u001b[39m\u001b[34m(self, prompt, ident, parent, password)\u001b[39m\n\u001b[32m 1322\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[32m 1323\u001b[39m \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[32m 1324\u001b[39m msg = \u001b[33m\"\u001b[39m\u001b[33mInterrupted by user\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m-> \u001b[39m\u001b[32m1325\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(msg) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1326\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[32m 1327\u001b[39m \u001b[38;5;28mself\u001b[39m.log.warning(\u001b[33m\"\u001b[39m\u001b[33mInvalid Message:\u001b[39m\u001b[33m\"\u001b[39m, exc_info=\u001b[38;5;28;01mTrue\u001b[39;00m)\n", + "\u001b[31mKeyboardInterrupt\u001b[39m: Interrupted by user" + ] + } + ], + "source": [ + "# Paso 4: Probar el código introduciendo entradas inválidas\n", + "\n", + "# Definir productos de ejemplo\n", + "productos = [\"manzana\", \"banana\", \"naranja\"]\n", + "\n", + "# Inicializar inventario con manejo de errores\n", + "inventario = initialize_inventory(productos)\n", + "\n", + "# Inicializar precios con manejo de errores\n", + "precios = calculate_total_price(productos)\n", + "\n", + "# Obtener pedidos de clientes con manejo de errores\n", + "pedidos = get_customer_orders(inventario)\n", + "\n", + "print(\"Inventario final:\", inventario)\n", + "print(\"Precios:\", precios)\n", + "print(\"Pedidos del cliente:\", pedidos)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "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.13.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}