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
119 changes: 117 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"# Lab | Data Structures "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -50,11 +57,119 @@
"\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": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Please enter 3 products you want to order from the list:\n",
"\n",
"Products in customer order: {'book', 'shirt', 'pen'}\n",
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 75.0%\n",
"\n",
"Updated Inventory:\n",
"Shirt: 100\n",
"Cap: 100\n",
"book: 99\n",
"pen: 99\n"
]
}
],
"source": [
"# Define Product\n",
"\n",
"Products = [\"Shirt\",\"Cap\", \"book\", \"pen\"]\n",
"\n",
"# Create Empty dictionary\n",
"\n",
"Inventorty = {}\n",
"\n",
"# User input for product\n",
"\n",
"for Product in Products:\n",
" Quantity = int(input(f\"Enter the quantity of {Product} in inventory: \"))\n",
" Inventorty [Product] = Quantity\n",
"\n",
"# create an empty set called customer_orders\n",
"\n",
"customer_orders = set()\n",
"\n",
"# user to input three products they want to order\n",
"\n",
"print(\"\\nPlease enter 3 products you want to order from the list:\")\n",
"for i in range(3):\n",
" order_item = input(f\"Enter product {i+1} of 3: \").lower().strip()\n",
" customer_orders.add(order_item)\n",
"\n",
" \n",
" # print the Product in the customer_orders sets \n",
" \n",
"\n",
"print(\"\\nProducts in customer order:\", customer_orders)\n",
"\n",
"\n",
"#calulate order Statistics\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"tota_available = len(Products)\n",
"percentage_of_ordered = (total_products_ordered / len(Products)) * 100\n",
"\n",
"\n",
"#store the statistics in a Tuple\n",
"\n",
"order_status = (total_products_ordered, percentage_of_ordered)\n",
"\n",
"\n",
"# print the order status using given format\n",
"\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"\n",
"#update the inventory by subtracting 1 from the quantity of each ordered product\n",
"\n",
"for ordered_item in customer_orders:\n",
" if ordered_item in Inventorty:\n",
" Inventorty[ordered_item] -= 1\n",
"\n",
"\n",
"# print the updated inventory\n",
"\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in Inventorty.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +183,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down