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
106 changes: 102 additions & 4 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"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",
" Store these statistics in a tuple called `order_status`.\n",
"\n",
"8. Print the order statistics using the following format:\n",
" ```\n",
Expand All @@ -50,11 +49,110 @@
"\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": null,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #list of products"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory: {'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 5, 'keychain': 6}\n"
]
}
],
"source": [
"inventory = {} #empty dictionary to store inventory\n",
"\n",
"inventory[\"t-shirt\"] = int(input(\"Enter quantity of t-shirt: \"))\n",
"inventory[\"mug\"] = int(input(\"Enter quantity of mug: \"))\n",
"inventory[\"hat\"] = int(input(\"Enter quantity of hat: \"))\n",
"inventory[\"book\"] = int(input(\"Enter quantity of book: \"))\n",
"inventory[\"keychain\"] = int(input(\"Enter quantity of keychain: \"))\n",
" \n",
"print(\"Inventory:\", inventory)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory: {'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n",
"Customer orders: {'mug'}\n"
]
}
],
"source": [
"customer_orders = set() #empty set to store customer orders\n",
"\n",
"customer_orders.add(input(\"Enter first product to order: \"))\n",
"customer_orders.add(input(\"Enter second product to order: \"))\n",
"customer_orders.add(input(\"Enter third product to order: \"))\n",
"\n",
"print(\"Inventory:\", inventory)\n",
"print(\"Customer orders:\", customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order status (total products ordered, percentage ordered): (3, 60.0)\n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"print(\"Order status (total products ordered, percentage ordered):\", order_status)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory after fulfilling one order of each product: {'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n"
]
}
],
"source": [
"for product in inventory:\n",
" inventory[product] -= 1\n",
"print(\"Updated Inventory after fulfilling one order of each product:\", inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +166,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down