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
222 changes: 220 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,229 @@
"\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": 61,
"metadata": {},
"outputs": [],
"source": [
"#1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"products= [\"tshirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#2. Create an empty dictionary called `inventory`."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"valor_tshirt = int(input(\"Enter the quantity of tshirts available: \"))\n",
"valor_mug = int(input(\"Enter the quantity of mugs available: \"))\n",
"valor_hat = int(input(\"Enter the quantity of hats available: \"))\n",
"valor_book = int(input(\"Enter the quantity of books available: \"))\n",
"valor_keychain = int(input(\"Enter the quantity of keychains available: \"))"
]
},
{
"cell_type": "code",
"execution_count": 99,
"metadata": {},
"outputs": [],
"source": [
"#4. Create an empty set called `customer_orders`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"customer_order = ()"
]
},
{
"cell_type": "code",
"execution_count": 119,
"metadata": {},
"outputs": [],
"source": [
"#5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"products = [\"tshirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"customer_orders = set()\n",
"product1 = input(\"Ingresa el nombre del primer producto que deseas: \").lower()\n",
"product2 = input(\"Ingresa el nombre del segundo producto que deseas: \").lower()\n",
"product3 = input(\"Ingresa el nombre del tercer producto que deseas: \").lower()\n",
"customer_orders.add(product1)\n",
"customer_orders.add(product2)\n",
"customer_orders.add(product3)"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [],
"source": [
"#6. Print the products in the `customer_orders` set."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'tshirt', 'mug'}\n"
]
}
],
"source": [
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#7. Calculate the following order statistics:\n",
"#. Total Products Ordered: The total number of products in the `customer_orders` set.\n",
"# Percentage of Products Ordered: The percentage of products ordered compared to the total available products."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order statistics:\n",
"Total products ordered: 3\n",
"Percentage of products ordered: 60.0%\n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"print(\"Order statistics:\")\n",
"print(f\"Total products ordered: {order_status[0]}\")\n",
"print(f\"Percentage of products ordered: {order_status[1]}%\")\n"
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {},
"outputs": [],
"source": [
"#9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"inventory[\"tshirt\"] = valor_tshirt - 1\n",
"inventory[\"mug\"] = valor_mug - 1\n",
"inventory[\"hat\"] = valor_hat - 1\n",
"inventory[\"book\"] = valor_book - 1\n",
"inventory[\"keychain\"] = valor_keychain - 1"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated inventory:\n",
"t-shirt: 4\n",
"mug: 4\n",
"hat: 4\n",
"book: 4\n",
"keychain: 4\n"
]
}
],
"source": [
"print(\"Updated inventory:\")\n",
"print(\"t-shirt:\", inventory[\"tshirt\"])\n",
"print(\"mug:\", inventory[\"mug\"])\n",
"print(\"hat:\", inventory[\"hat\"])\n",
"print(\"book:\", inventory[\"book\"])\n",
"print(\"keychain:\", inventory[\"keychain\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +286,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down