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
100 changes: 98 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer orders: {'hat', 'mug', 'book'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"Updated Inventory:\n",
"t-shirt: 13\n",
"mug: 1\n",
"hat: 7\n",
"book: 89\n",
"keychain: 40\n"
]
}
],
"source": [
"\n",
"# step 1: define product list\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"\n",
"\n",
"# step 2: create empty inventory dictionary\n",
"\n",
"inventory = {}\n",
"\n",
"\n",
"\n",
"# step 3: ask user for quantity of each product\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity for {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"\n",
"\n",
"# step 4: create empty set for customer orders\n",
"\n",
"customer_orders = set()\n",
"\n",
"\n",
"\n",
"# step 5: ask user to input 3 products to order\n",
"\n",
"for i in range(3):\n",
" product = input(f\"Enter product {i + 1} to order: \")\n",
" customer_orders.add(product)\n",
"\n",
"\n",
"\n",
"# step 6: print customer orders\n",
"\n",
"print(\"Customer orders:\", customer_orders)\n",
"\n",
"\n",
"\n",
"# step 7: calculate statistics and store in tuple\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(f\"Total products ordered: {total_products_ordered}\")\n",
"#print(f\"Percentage of products ordered: {percentage_ordered}%\")\n",
"#print(\"Order status tuple:\", order_status)\n",
"\n",
"\n",
"# step 8: print order statistics in required format\n",
"\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {total_products_ordered}\")\n",
"print(f\"Percentage of Products Ordered: {percentage_ordered}%\")\n",
"\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"\n",
"# step 10: print updated inventory\n",
"\n",
"print(\"Updated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -54,7 +150,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down