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
294 changes: 290 additions & 4 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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",
" percentage_ordered \n",
" Store these statistics in a tuple called `order_status`.\n",
"\n",
"8. Print the order statistics using the following format:\n",
Expand All @@ -50,13 +50,299 @@
"\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\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"inventory={}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of t-shirt available in the inventory: 22\n"
]
}
],
"source": [
"inventory[\"t-shirt\"]=int(input(\"quantity of t-shirt available in the inventory: \"))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of mug available in the inventory: 32\n"
]
}
],
"source": [
"inventory[\"mug\"]=int(input(\"quantity of mug available in the inventory: \"))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of hat available in the inventory: 45\n"
]
}
],
"source": [
"inventory[\"hat\"]=int(input(\"quantity of hat available in the inventory: \"))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of book available in the inventory: 56\n"
]
}
],
"source": [
"inventory[\"book\"]=int(input(\"quantity of book available in the inventory: \"))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of keychain available in the inventory: 72\n"
]
}
],
"source": [
"inventory[\"keychain\"]=int(input(\"quantity of keychain available in the inventory: \"))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"customer_orders=set() \n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"input order1: mug\n",
"input order2: hat\n",
"input order3: book\n"
]
}
],
"source": [
"x=input(\"input order1: \")\n",
"y=input(\"input order2: \")\n",
"z=input(\"input order3: \")\n",
"customer_orders.add(x)\n",
"customer_orders.add(y)\n",
"customer_orders.add(z)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'hat', 'mug'}\n"
]
}
],
"source": [
"print(customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"total_products_ordered=len(customer_orders)\n",
"print(total_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"percentage_ordered=len(customer_orders)/len(products)*100"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"order_status=(total_products_ordered,percentage_ordered)"
]
},
{
"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": [
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered: \"+ str(total_products_ordered))\n",
"print(\"Percentage of Products Ordered: \"+ str(percentage_ordered))"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"for item in customer_orders:\n",
" inventory[item]=inventory[item]-1\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 22, 'mug': 31, 'hat': 44, 'book': 55, 'keychain': 72}\n"
]
}
],
"source": [
"print (inventory)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('t-shirt', 22)\n",
"('mug', 31)\n",
"('hat', 44)\n",
"('book', 55)\n",
"('keychain', 72)\n"
]
}
],
"source": [
"for item in inventory.items() :\n",
" print(item)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_items([('t-shirt', 22), ('mug', 31), ('hat', 44), ('book', 55), ('keychain', 72)])\n"
]
}
],
"source": [
"print(inventory.items())"
]
},
{
"cell_type": "code",
"execution_count": null,
"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,7 +354,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down