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
158 changes: 156 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,165 @@
"\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": [],
"source": [
"inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n",
"inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n",
"inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n",
"inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n",
"inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"product1 = input(\"Enter the first product: \")\n",
"customer_orders.add(product1)\n",
"product2 = input(\"Enter the second product: \")\n",
"customer_orders.add(product2)\n",
"product3 = input(\"Enter the third product: \")\n",
"customer_orders.add(product3)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'mug', 'book'}\n"
]
}
],
"source": [
"print (customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"products_ordered = len (customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"percentage_ordered = (products_ordered / len (products) * 100)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"order_status = (products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"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 (f\"total products ordered: {products_ordered}\")\n",
"print (f\"Percentage of products ordered: {percentage_ordered}\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"for product in inventory:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 2\n",
"mug: 3\n",
"hat: 4\n",
"book: 5\n",
"keychain: 6\n"
]
}
],
"source": [
"print (f\"t-shirt: {inventory[\"t-shirt\"]}\")\n",
"print (f\"mug: {inventory[\"mug\"]}\")\n",
"print (f\"hat: {inventory[\"hat\"]}\") \n",
"print (f\"book: {inventory[\"book\"]}\") \n",
"print (f\"keychain: {inventory[\"keychain\"]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +222,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down