Skip to content

Actualización del notebook desde Jupyter #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 117 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,122 @@
"\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": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the quantity available for each product:\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"t-shirt: 5\n",
"mug: 3\n",
"hat: 2\n",
"book: 4\n",
"keychain: 6\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Enter 3 products the customer wants to order (from the list):\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Product 1: mug\n",
"Product 2: hat\n",
"Product 3: mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Customer Orders:\n",
"Order Statistics:\n",
"Total Products Ordered: 2\n",
"Percentage of Products Ordered: 40.0%\n",
" Updated Inventory:\n",
"t-shirt: 5\n",
"mug: 2\n",
"hat: 1\n",
"book: 4\n",
"keychain: 6\n"
]
}
],
"source": [
"# Paso 1: Lista de productos\n",
"products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Paso 2: Diccionario vacío para el inventario\n",
"inventory = {}\n",
"\n",
"# Paso 3: Pedir al usuario que ingrese la cantidad disponible de cada producto\n",
"print(\"Enter the quantity available for each product:\")\n",
"for product in products:\n",
" quantity = int(input(f\"{product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"# Paso 4: Conjunto vacío para los pedidos del cliente\n",
"customer_orders = set()\n",
"\n",
"# Paso 5: Pedir 3 productos y agregarlos al conjunto\n",
"print(\"\\nEnter 3 products the customer wants to order (from the list):\")\n",
"order1 = input(\"Product 1: \").strip().lower()\n",
"order2 = input(\"Product 2: \").strip().lower()\n",
"order3 = input(\"Product 3: \").strip().lower()\n",
"\n",
"customer_orders.add(order1)\n",
"customer_orders.add(order2)\n",
"customer_orders.add(order3)\n",
"\n",
"# Paso 6: Imprimir los productos ordenados\n",
"print(\" Customer Orders:\")\n",
"\n",
"# Paso 7: Calcular estadísticas del pedido\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, round(percentage_ordered, 2))\n",
"\n",
"# Paso 8: Imprimir estadísticas del pedido\n",
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", order_status[0])\n",
"print(\"Percentage of Products Ordered:\", f\"{order_status[1]}%\")\n",
"\n",
"# Paso 9: Actualizar inventario restando 1 por cada producto pedido\n",
"for item in customer_orders:\n",
" if item in inventory and inventory[item] > 0:\n",
" inventory[item] -= 1\n",
" else:\n",
" print(f\" Not enough stock or unknown product: {item}\")\n",
"\n",
"# Paso 10: Imprimir inventario actualizado\n",
"print(\" Updated Inventory:\")\n",
"for product, qty in inventory.items():\n",
" print(f\"{product}: {qty}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +184,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down