diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..aab233df 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,107 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Productos pedidos:\n", + "mug\n", + "t-shirt\n", + "hat\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n", + "Inventario actualizado:\n", + "t-shirt: 5\n", + "mug: 5\n", + "hat: 7\n", + "book: 15\n", + "keychain: 22\n" + ] + } + ], + "source": [ + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "inventory = {}\n", + "\n", + "# Paso 3\n", + "\n", + "\n", + "cantidad_tshirt = int(input(\"¿Cuánt@s t-shirt hay en inventario? \"))\n", + "cantidad_mug = int(input(\"¿Cuánt@s mug hay en inventario? \"))\n", + "cantidad_hat = int(input(\"¿Cuánt@s hat hay en inventario? \"))\n", + "cantidad_book = int(input(\"¿Cuánt@s book hay en inventario? \"))\n", + "cantidad_keychain = int(input(\"¿Cuánt@s keychain hay en inventario? \"))\n", + "\n", + "inventory[\"t-shirt\"] = cantidad_tshirt\n", + "inventory[\"mug\"] = cantidad_mug\n", + "inventory[\"hat\"] = cantidad_hat\n", + "inventory[\"book\"] = cantidad_book\n", + "inventory[\"keychain\"] = cantidad_keychain\n", + "\n", + "# Paso 4\n", + "customer_orders = set()\n", + "\n", + "# Paso 5\n", + "producto1 = input(\"Introduce el primer producto que desea pedir: \")\n", + "producto2 = input(\"Introduce el segundo producto que desea pedir: \")\n", + "producto3 = input(\"Introduce el tercer producto que desea pedir: \")\n", + "\n", + "customer_orders.add(producto1)\n", + "customer_orders.add(producto2)\n", + "customer_orders.add(producto3)\n", + "\n", + "# Paso 6\n", + "print(\"Productos pedidos:\")\n", + "for producto in customer_orders:\n", + " print(producto)\n", + "\n", + "# Paso 7: Calcular las estadísticas del pedido\n", + "total_products_ordered = len(customer_orders) # Total de productos pedidos\n", + "total_available_products = len(products) # Total de productos disponibles\n", + "percentage_ordered = (total_products_ordered / total_available_products) * 100\n", + "order_status = (total_products_ordered, percentage_ordered) # Tupla con las estadísticas\n", + "\n", + "# Paso 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Paso 9\n", + "if \"t-shirt\" in customer_orders:\n", + " inventory[\"t-shirt\"] -= 1\n", + "if \"mug\" in customer_orders:\n", + " inventory[\"mug\"] -= 1\n", + "if \"hat\" in customer_orders:\n", + " inventory[\"hat\"] -= 1\n", + "if \"book\" in customer_orders:\n", + " inventory[\"book\"] -= 1\n", + "if \"keychain\" in customer_orders:\n", + " inventory[\"keychain\"] -= 1\n", + "\n", + "# Paso 10\n", + "print(\"Inventario actualizado:\")\n", + "print(\"t-shirt:\", inventory[\"t-shirt\"])\n", + "print(\"mug:\", inventory[\"mug\"])\n", + "print(\"hat:\", inventory[\"hat\"])\n", + "print(\"book:\", inventory[\"book\"])\n", + "print(\"keychain:\", inventory[\"keychain\"])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +164,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4,