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
264 changes: 261 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,271 @@
"\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": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"
]
}
],
"source": [
"# 1\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"print(products)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#2\n",
"inventory={ }"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"enter the qty of each ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 4\n",
"enter the qty of each ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 5\n",
"enter the qty of each ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 6\n",
"enter the qty of each ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 7\n",
"enter the qty of each ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 3\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"current inventory is: 3\n"
]
}
],
"source": [
"#3 option 1\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={ }\n",
"for product in products: #iteration - loop\n",
" qty = int(input(f\"enter the qty of each {products}\"))\n",
"print('current inventory is:',qty)\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt:4\n",
"mug:5\n",
"hat:6\n",
"book:7\n",
"keychain:3\n"
]
}
],
"source": [
"#3 option 2\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={\"t-shirt\":4, \"mug\":5, \"hat\":6, \"book\":7, \"keychain\":3}\n",
"for product, qty in inventory.items(): \n",
" print(f\"{product}:{qty}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#4\n",
"customer_orders = ()\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"enter 3 products from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n",
"enter 3 products from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n",
"enter 3 products from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"the customer orders are:,{'mug', 'book', 'hat'}\n",
"{'mug', 'book', 'hat'}\n"
]
}
],
"source": [
"#5\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"customer_orders = set() #empty set to be populated\n",
"for i in range(3): \n",
" product_to_order = input(f'enter 3 products from {products}')\n",
" if product_to_order in products:\n",
" customer_orders.add(product_to_order)\n",
" else:\n",
" print(f'invalid')\n",
"print(f\"the customer orders are:,{customer_orders}\")\n",
"print(customer_orders)\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'book', 'hat'}\n"
]
}
],
"source": [
"#6\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"60.0\n",
"order_status is: (60.0, 3)\n"
]
}
],
"source": [
"#7\n",
"customer_order = {'mug', 'book', 'hat'}\n",
"total_products_order = len(customer_order)\n",
"print(total_products_order)\n",
"percentage_of_products_ordered= len(customer_order) /len(products)*100\n",
"print(percentage_of_products_ordered)\n",
"order_status = (percentage_of_products_ordered, total_products_order)\n",
"print('order_status is:', order_status)\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"60.0\n"
]
}
],
"source": [
"#8\n",
"print(total_products_order)\n",
"print(percentage_of_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the updated inventory is: {'t-shirt': 3, 'mug': 4, 'hat': 5, 'book': 6, 'keychain': 2}\n"
]
}
],
"source": [
"#9\n",
"inventory={\"t-shirt\":4, \"mug\":5, \"hat\":6, \"book\":7, \"keychain\":3}\n",
"for product in inventory:\n",
" inventory[product] -=1\n",
"print(f'the updated inventory is:',inventory)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt:3\n",
"mug:4\n",
"hat:5\n",
"book:6\n",
"keychain:2\n"
]
}
],
"source": [
"#10\n",
"for product, qty in inventory.items():\n",
" print(f\"{product}:{qty}\")"
]
},
{
"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 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down