diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..8dfe1e4 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,99 @@ "\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": null, + "id": "13fa8b8f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Productos pedidos: {'keychain', 'book', 'hat'}\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n", + "\n", + "Inventario actualizado:\n", + "t-shirt : 20\n", + "mug : 20\n", + "hat : 19\n", + "book : 19\n", + "keychain : 19\n" + ] + } + ], + "source": [ + "# Lista de productos disponibles\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Diccionario vacío para el inventario\n", + "inventory = {}\n", + "\n", + "# Pedir al usuario la cantidad de cada producto\n", + "for product in products:\n", + " quantity = int(input(f\"Introduce la cantidad de los productos ({product}): \"))\n", + " inventory[product] = quantity\n", + "\n", + "# Conjunto vacío para los pedidos del cliente\n", + "customers_orders = set()\n", + "\n", + "# Pedir al cliente tres productos\n", + "\n", + "while True:\n", + "\n", + " order = input(\"Elige productos para pedir (t-shirt, mug, hat, book, keychain) o exit si no quieres nada:\").strip().lower()\n", + "\n", + " if order in (\"exit\", \"salir\"):\n", + " print(\"Saliendo del programa.\")\n", + " break\n", + "\n", + " if order in products:\n", + " customers_orders.add(order)\n", + " o = input(\"Quieres añadir otro prodructo? (yes/no)\").strip().lower()\n", + " if o == \"no\":\n", + " break\n", + " if o == \"yes\":\n", + " continue\n", + " \n", + " \n", + " else:\n", + " print(f\"El producto {order} no está disponible.\")\n", + " continue\n", + "\n", + " \n", + "\n", + "\n", + "# Mostrar los pedidos\n", + "print(\"Productos pedidos:\", customers_orders)\n", + "\n", + "# Calcular estadísticas\n", + "total_products_ordered = len(customers_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "# Mostrar estadísticas\n", + "print(\"\\nOrder Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")\n", + "\n", + "# Actualizar inventario\n", + "for item in customers_orders:\n", + " inventory[item] = inventory[item] - 1\n", + "\n", + "# Mostrar inventario actualizado\n", + "print(\"\\nInventario actualizado:\")\n", + "for product in inventory:\n", + " print(product, \":\", inventory[product])\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.9" } }, "nbformat": 4,