Skip to content
Closed
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
293 changes: 247 additions & 46 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
@@ -1,62 +1,263 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"cell_type": "code",
"execution_count": 1,
"id": "233b272f-a88d-49fe-baa7-d2d024d97c07",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"products = [\"t-shirt\", \"mug\" , \"hat\" , \"book\" , \"keychain\"]\n",
"products"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fb080810-bb49-49d5-b795-6144e8968c99",
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b793076d-d9de-4fdf-9ef1-d6f6e0d50197",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity for t-shirt: 10\n",
"Enter the quantity for mug: 20\n",
"Enter the quantity for hat: 40\n",
"Enter the quantity for book: 18\n",
"Enter the quantity for keychain: 88\n"
]
}
],
"source": [
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity for {product}: \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4ccce103-c989-4846-987d-64035ab91373",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "ea127f4f-ab74-4822-8d72-1b3694d0ccc4",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the name of a productyou want to order: mug\n",
"Enter the name of a productyou want to order: book\n",
"Enter the name of a productyou want to order: keychain\n"
]
}
],
"source": [
"for k in range(3):\n",
" order = input(\"Enter the name of a productyou want to order: \")\n",
" customer_orders.add(order)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "09deeb9b-19e1-4db0-989b-0299a730e95d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Products in Customer Orders: {'keychain', 'mug', 'book'}\n"
]
}
],
"source": [
"print(\"\\nProducts in Customer Orders:\", customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ace4986d-ae42-4140-a1b7-ef4ecdaf93dc",
"metadata": {},
"outputs": [],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_products_ordered = (total_products_ordered / len(products))* 100\n",
"order_status = (total_products_ordered, percentage_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "66d00454-8841-42ff-8e2d-e5be089c428a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage Products Ordered: 60.0%\n"
]
}
],
"source": [
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage Products Ordered: {order_status[1]}%\")\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "0102ef7b-1bda-4339-ba23-15eec4b0afa3",
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "e1c8e5b0-6eec-4e22-bbe9-6da1f1d365af",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Updated Inventory:\n",
"t-shirt: 10\n",
"mug: 19\n",
"hat: 40\n",
"book: 17\n",
"keychain: 87\n"
]
}
],
"source": [
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "90f9db31-e8b9-4761-a98e-8c162f5205c0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CompletedProcess(args=['git', 'add', 'lab-python-data-structures.ipynb'], returncode=0)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Lab | Data Structures "
"import subprocess\n",
"subprocess.run([\"git\", \"add\", \"lab-python-data-structures.ipynb\"])"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": 21,
"id": "c1aacb6d-d94f-4c82-bff9-8d4943f11106",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CompletedProcess(args=['git', 'commit', '-m', 'Completed all exercised'], returncode=0)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Exercise: Managing Customer Orders\n",
"\n",
"As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n",
"\n",
"Follow the steps below to complete the exercise:\n",
"\n",
"1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n",
"\n",
"2. Create an empty dictionary called `inventory`.\n",
"\n",
"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",
"\n",
"4. Create an empty set called `customer_orders`.\n",
"\n",
"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.\n",
"\n",
"6. Print the products in the `customer_orders` set.\n",
"\n",
"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.\n",
" \n",
" Store these statistics in a tuple called `order_status`.\n",
"\n",
"8. Print the order statistics using the following format:\n",
" ```\n",
" Order Statistics:\n",
" Total Products Ordered: <total_products_ordered>\n",
" Percentage of Products Ordered: <percentage_ordered>% \n",
" ```\n",
"\n",
"9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n",
"\n",
"10. Print the updated inventory, displaying the quantity of each product on separate lines.\n",
"\n",
"Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. "
"subprocess.run([\"git\", \"commit\", \"-m\", \"Completed all exercised\"])"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "75689911-024c-4114-b402-1cec2dd2693e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CompletedProcess(args=['git', 'push', 'origin', 'main'], returncode=1)"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subprocess.run([\"git\", \"push\", \"origin\", \"main\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "289efc73-3a4f-4102-a824-1f0020c04fe8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -68,9 +269,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
"nbformat_minor": 5
}