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
68 changes: 65 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise: Managing Customer Orders\n",
"## 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",
Expand Down Expand Up @@ -50,11 +50,73 @@
"\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": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The customer has ordered {'mug', 'hat', 'book'}\n",
"\n",
"Order Statistics:\n",
" Total Products Ordered: <3>\n",
" Percentage of Products Ordered: <60.0>%\n",
"\n",
"The actual quantity of item t-shirt is: 1\n",
"The actual quantity of item mug is: 0\n",
"The actual quantity of item hat is: 0\n",
"The actual quantity of item book is: 0\n",
"The actual quantity of item keychain is: 1\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set()\n",
"for i in range (3):\n",
" order = input('Enter the name of three products. Choose between \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\": ')\n",
" if order in products:\n",
" customer_orders.add(order)\n",
"\n",
"print (f\"The customer has ordered {customer_orders}\" \"\\n\")\n",
"\n",
"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",
"\n",
"print (\"Order Statistics:\" \"\\n\", \n",
"f\"Total Products Ordered: {total_products_ordered}\" \"\\n\",\n",
"f\"Percentage of Products Ordered: {percentage_ordered}%\" \"\\n\")\n",
"\n",
"for order in customer_orders:\n",
" if order in products:\n",
" inventory[order] -= 1\n",
"\n",
"for key,value in inventory.items():\n",
" print (f\"The actual quantity of item {key} is: {value}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv-bootcamp (3.14.3)",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.3"
}
},
"nbformat": 4,
Expand Down