Skip to content
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
181 changes: 179 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,188 @@
"\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": 24,
"metadata": {},
"outputs": [],
"source": [
"# crear una lista llamada products\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# crear un diccionario vacío llamado inventory\n",
"\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# solicitar la cantidad de cada producto para poner en Inventory, usando los productos de products como keys y las cantidades como values\n",
"\n",
"tshirt_quant = int(input(\"put the number of t-shirts\"))\n",
"mug_quant = int(input(\"put the number of mugs\"))\n",
"hat_quant = int(input(\"put the number of hats\"))\n",
"books_quant = int(input(\"put the number of books\"))\n",
"keychain_quant = int(input(\"put the number of keychains\"))\n",
"\n",
"inventory[products[0]] = tshirt_quant\n",
"inventory[products[1]] = mug_quant\n",
"inventory[products[2]] = hat_quant\n",
"inventory[products[3]] = books_quant\n",
"inventory[products[4]] = keychain_quant\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 89, 'mug': 55, 'hat': 63, 'book': 78, 'keychain': 50}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"# crear un set vacío que sea costumer_orders\n",
"\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'keychain', 'mug'}\n"
]
}
],
"source": [
"# pedir al cliente que seleccione 3 prodcutos de la lista products\n",
"\n",
"customer_prod_1 = input(\"select a product\")\n",
"customer_prod_2 = input(\"select a product\")\n",
"customer_prod_3 = input(\"select a product\")\n",
"\n",
"customer_orders.add(customer_prod_1)\n",
"customer_orders.add(customer_prod_2)\n",
"customer_orders.add(customer_prod_3)\n",
"\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"# calcular el total de productos pedidos y el porcentaje correspondiente sobre la lista total de productos\n",
"\n",
"\n",
"porcentaje_pedido = (len(customer_orders) / len(products)) * 100\n",
"order_status = (len(customer_orders), porcentaje_pedido)\n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0\n"
]
}
],
"source": [
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", order_status[0])\n",
"print(\"Percentage of Products Ordered:\", order_status[1])"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# restar 1 a la cantidad de cada producto en inventory por cada producto en customer_orders\n",
"\n",
"for product_name in inventory:\n",
" # Resta 1 a la cantidad del producto actual\n",
" inventory[product_name] = inventory[product_name] - 1\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Inventario Actualizado:\n",
"t-shirt: 88\n",
"mug: 54\n",
"hat: 62\n",
"book: 77\n",
"keychain: 49\n"
]
}
],
"source": [
"print(\"\\nInventario Actualizado:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down