diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..3768c71 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,120 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "877bb818", + "metadata": {}, + "outputs": [], + "source": [ + "# Paso 1: productos disponibles\n", + "products = [\"camisetas\", \"mug\", \"gorras\", \"libros\", \"llaveros\"]\n", + "\n", + "# Paso 2: inventario\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "b45abc05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Introduce el stock de cada producto:\n", + "{'camisetas': 20, 'mug': 10, 'gorras': 30, 'libros': 50, 'llaveros': 50}\n" + ] + } + ], + "source": [ + "print(\"Introduce el stock de cada producto:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# Paso 3: set de pedidos\n", + "customer_orders = set()\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "0eb94716", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Producto inválido. Usa uno de estos: ['camisetas', 'mug', 'gorras', 'libros', 'llaveros']\n", + "\n", + "Productos pedidos:\n", + "{'llaveros', 'camisetas', 'gorras'}\n" + ] + } + ], + "source": [ + "# Paso 4: pedir productos usando bucle\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", + "\n", + " if another not in (\"si\", \"sí\", \"s\"):\n", + " break\n", + "\n", + "# Paso 5: mostrar productos pedidos\n", + "print(\"\\nProductos pedidos:\")\n", + "print(customer_orders)\n", + "\n", + "# Paso 6: actualizar inventario SOLO de productos pedidos\n", + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "7ed6fc16", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Inventario actualizado:\n", + "camisetas : 19\n", + "mug : 10\n", + "gorras : 29\n", + "libros : 50\n", + "llaveros : 49\n" + ] + } + ], + "source": [ + "# Paso 7: mostrar inventario actualizado\n", + "print(\"\\nInventario actualizado:\")\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +164,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.0" } }, "nbformat": 4,