Skip to content
Open

tarea #580

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
144 changes: 142 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,151 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "779c2b1d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Productos disponibles: ['camiseta', 'taza', 'sombrero', 'libro', 'llavero']\n"
]
}
],
"source": [
"productos=[\"camiseta\",\"taza\",\"sombrero\",\"libro\",\"llavero\"]\n",
"print(f\"Productos disponibles: {productos}\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2c527b71",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventario(productos):\n",
" inventario = {}\n",
" for producto in productos:\n",
" cantidad = int(input(f\"Ingrese la cantidad de {producto} que desea agregar al inventario: \"))\n",
" inventario[producto] = cantidad\n",
" return inventario \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "877ba483",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders=set()\n",
" \n",
" while True:\n",
" product = input(\"¿Qué producto desea comprar? \")\n",
" customer_orders.add(product)\n",
" continuar = input(\"¿Desea agregar otro producto? (si/no): \")\n",
" if continuar.lower() != 'si':\n",
" break\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ca45f0dc",
"metadata": {},
"outputs": [],
"source": [
"def update_inventario(inventario, customer_orders):\n",
" for producto in customer_orders:\n",
" if producto in inventario and inventario[producto] > 0:\n",
" inventario[producto] -= 1\n",
" else:\n",
" print(f\"Lo siento, {producto} no está disponible en el inventario.\")\n",
" return inventario"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2c2f6820",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, productos):\n",
" total_pedidos = len(customer_orders)\n",
" porcentaje_comprados = (total_pedidos / len(productos)) * 100\n",
" return total_pedidos, porcentaje_comprados"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "cd8acfbb",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" print(f\"Total de productos pedidos: {order_statistics[0]}\")\n",
" print(f\"Porcentaje de productos únicos pedidos: {order_statistics[1]:.2f}%\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "f7a916e7",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventario(nuevo_inventario):\n",
" print(\"Inventario actualizado:\")\n",
" for producto, cantidad in nuevo_inventario.items():\n",
" print(f\"{producto}: {cantidad}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1aee4cef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Lo siento, 1 no está disponible en el inventario.\n",
"Total de productos pedidos: 1\n",
"Porcentaje de productos únicos pedidos: 20.00%\n",
"Inventario actualizado:\n",
"camiseta: 6\n",
"taza: 8\n",
"sombrero: 4\n",
"libro: 7\n",
"llavero: 5\n"
]
}
],
"source": [
"productos = [\"camiseta\", \"taza\", \"sombrero\", \"libro\", \"llavero\"]\n",
"inventario = initialize_inventario(productos)\n",
"customer_orders = get_customer_orders()\n",
"inventario = update_inventario(inventario, customer_orders)\n",
"estadisticas = calculate_order_statistics(customer_orders, productos)\n",
"print_order_statistics(estadisticas)\n",
"print_updated_inventario(inventario)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +201,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down