diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..8f1c525 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,108 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "ddf14b24", + "metadata": {}, + "outputs": [], + "source": [ + "# Productos\n", + "products = [\"camisetas\", \"mug\", \"gorras\", \"libros\", \"llaveros\"]\n", + "\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " print(\"Introduce el stock de cada producto:\")\n", + " for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "\n", + "def get_customer_orders(products):\n", + " customer_orders = set()\n", + " while True:\n", + " product = input(\"Ingresa el nombre del producto que deseas ordenar: \").lower()\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Producto inválido. Usa uno de estos:\", products)\n", + " continue\n", + "\n", + " another = input(\"¿Deseas agregar otro producto? (si/no): \").lower()\n", + " if another not in (\"si\", \"sí\", \"s\"):\n", + " break\n", + "\n", + " return customer_orders\n", + "\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "\n", + "def print_inventory(inventory):\n", + " print(\"\\nInventario actualizado:\")\n", + " for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12a87c44", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Introduce el stock de cada producto:\n", + "\n", + "Inventario actualizado:\n", + "camisetas : 20\n", + "mug : 10\n", + "gorras : 30\n", + "libros : 20\n", + "llaveros : 50\n", + "\n", + "Productos pedidos: {'llaveros', 'gorras', 'camisetas'}\n", + "\n", + "Inventario actualizado:\n", + "camisetas : 19\n", + "mug : 10\n", + "gorras : 29\n", + "libros : 20\n", + "llaveros : 49\n" + ] + } + ], + "source": [ + "# 1️ Cargar inventario\n", + "inventory = initialize_inventory(products)\n", + "\n", + "# 2️ Mostrar inventario cargado\n", + "print_inventory(inventory)\n", + "\n", + "# 3️ Pedir productos al cliente\n", + "customer_orders = get_customer_orders(products)\n", + "print(\"\\nProductos pedidos:\", customer_orders)\n", + "\n", + "# 4️ Actualizar inventario\n", + "update_inventory(customer_orders, inventory)\n", + "\n", + "# 5️ Mostrar inventario final\n", + "print_inventory(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +158,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.0" } }, "nbformat": 4,