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
146 changes: 144 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,153 @@
"\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": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"for product in products:\n",
" quantity = int(input(f\"Introduce la cantidad de los productos {product}: \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"customers_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Elige tres productos para pedir (t-shirt, mug, hat, book, keychain):\n"
]
}
],
"source": [
"print(\"Elige tres productos para pedir (t-shirt, mug, hat, book, keychain):\")\n",
"for x in range(3):\n",
" order = input(f\"Producto {x+1}: \")\n",
" customers_orders.add(order)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Productos pedidos: {'hat', 'mug', 'book'}\n"
]
}
],
"source": [
"print(\"Productos pedidos:\", customers_orders)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"total_products_ordered = len(customers_orders) \n",
"percentage_ordered = (total_products_ordered / len(products)) * 100"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
],
"source": [
"print(\"\\nOrder Statistics:\")\n",
"print(\"Total Products Ordered:\", total_products_ordered)\n",
"print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"for item in customers_orders:\n",
" inventory[item] = inventory[item] - 1"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventario actualizado:\n",
"t-shirt : 20\n",
"mug : 19\n",
"hat : 19\n",
"book : 19\n",
"keychain : 20\n"
]
}
],
"source": [
"print(\"Inventario actualizado:\")\n",
"for product in inventory:\n",
" print(product, \":\", inventory[product])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +210,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down