diff --git a/lab-python-list-comprehension.ipynb b/lab-python-list-comprehension.ipynb index 5a3c3e1..ca79538 100644 --- a/lab-python-list-comprehension.ipynb +++ b/lab-python-list-comprehension.ipynb @@ -75,11 +75,194 @@ "\n", "```\n" ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "1ac5dc53", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1000, 'mug': 1000, 'hat': 1000, 'book': 1000, 'keychain': 1000}\n" + ] + } + ], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {product: int(input(f\"Introduce la cantidad de {product}s disponibles: \")) for product in products}\n", + " print(\"Inventario inicial:\", inventory)\n", + " return inventory\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "eea40492", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['book', 'hat', 'mug', 'book', 'book']\n" + ] + } + ], + "source": [ + "def get_customer_orders(products):\n", + " num_orders = int(input(\"Introduce el número de pedidos de clientes: \"))\n", + " customer_orders = []\n", + " for i in range(num_orders):\n", + " order = input(f\"Introduce el nombre del producto {i+1} que deseas comprar: \")\n", + " if order in products:\n", + " customer_orders.append(order)\n", + " else:\n", + " print(\"El producto no está disponible.\")\n", + " print(\"Productos pedidos por el cliente:\", customer_orders)\n", + " return customer_orders\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "fd2d8432", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total price of orders: 121.0 EUROS\n" + ] + } + ], + "source": [ + "def calculate_total_price(customer_orders):\n", + " total_price = sum(float(input(f\"Introduce el precio de {product}: \")) for product in customer_orders)\n", + " print(f\"Precio Total: {total_price}\")\n", + " return total_price\n", + "print(\"Total price of orders:\", total_price, \"EUROS\")" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "69adbebc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory: {'mug': 999, 'hat': 999, 'book': 999}\n" + ] + } + ], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " updated_inventory = {product: inventory[product] - 1 for product in inventory if product in customer_orders and inventory[product] > 0}\n", + " print(\"Inventario actualizado:\")\n", + " for product, quantity in updated_inventory.items():\n", + " print(product, \":\", quantity)\n", + " return updated_inventory\n", + "print(\"Updated inventory:\", updated_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4b2b5a8", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + " return total_products_ordered, percentage_ordered\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "16ffdc0e", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_ordered = order_statistics\n", + " print(\"Estadísticas del Pedido:\")\n", + " print(\"Total de productos pedidos:\", total_products_ordered)\n", + " print(\"Porcentaje de productos únicos pedidos:\", percentage_ordered, \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "c4c30469", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"Inventario actualizado:\")\n", + " for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "ae66e5ca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventario inicial: {'t-shirt': 1000, 'mug': 1000, 'hat': 1000, 'book': 1000, 'keychain': 1000}\n", + "Productos pedidos por el cliente: ['book', 'hat', 'mug', 'book', 'book']\n", + "Estadísticas del Pedido:\n", + "Total de productos pedidos: 5\n", + "Porcentaje de productos únicos pedidos: 100.0 %\n", + "Precio Total: 121.0\n", + "Inventario actualizado:\n", + "mug : 999\n", + "hat : 999\n", + "book : 999\n" + ] + } + ], + "source": [ + "## Lista de productos disponibles\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 1: Inicializamos el inventario\n", + "inventory = initialize_inventory(products)\n", + "\n", + "# Paso 2: Obtenemos los pedidos del cliente\n", + "customer_orders = get_customer_orders(products) # Asegúrate de pasar 'products' aquí porque si no, da error\n", + "\n", + "# Paso 3: Calculamos las estadísticas\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "# Paso 4: Mostramos las estadísticas\n", + "print_order_statistics(order_statistics)\n", + "\n", + "# Paso 5: Calculamos el precio total del pedido\n", + "total_price = calculate_total_price(customer_orders)\n", + "\n", + "# Paso 6: Actualizamos el inventario\n", + "updated_inventory = update_inventory(customer_orders, inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -93,7 +276,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.10" } }, "nbformat": 4,