Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
93 changes: 91 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,100 @@
"\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': 100}\n",
"{'t-shirt': 100, 'mug': 150}\n",
"{'t-shirt': 100, 'mug': 150, 'hat': 200}\n",
"{'t-shirt': 100, 'mug': 150, 'hat': 200, 'book': 1800}\n",
"{'t-shirt': 100, 'mug': 150, 'hat': 200, 'book': 1800, 'keychain': 4}\n",
"Sorry, 'bool' is not in our product list. Please choose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"Sorry, 'keichan' is not in our product list. Please choose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"\n",
"Customer Orders:\n",
"book\n",
"mug\n",
"t-shirt\n",
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"\n",
"Updated Inventory:\n",
"t-shirt: 99\n",
"mug: 149\n",
"hat: 200\n",
"book: 1799\n",
"keychain: 4\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #Step 1: List definition\n",
"inventory = {} #Step 2: Empty dictionary definition\n",
"for product in products:\n",
" inventory[product] = int(input(f\"Enter the quantity of {product} in stock: \")) #Step 3: Prompt user for input\n",
" print(inventory)\n",
"# Step 4: Create an empty set called customer_orders\n",
"customer_orders = set()\n",
"\n",
"# Step 5: Ask user to input 3 products they want to order\n",
"for i in range(3):\n",
" while True:\n",
" order = input(f\"Enter product {i+1} to order from {products}: \")\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" break\n",
" else:\n",
" print(f\"Sorry, '{order}' is not in our product list. Please choose from {products}\")\n",
"\n",
"# Step 6: Print the products in customer_orders set\n",
"print(\"\\nCustomer Orders:\")\n",
"for order in customer_orders:\n",
" print(order)\n",
"\n",
"# Step 7: Calculate order statistics\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"# Step 8: Print order statistics\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]:.1f}%\")\n",
"\n",
"# Step 9: Update inventory by subtracting 1 from each ordered product\n",
"for product in customer_orders:\n",
" if inventory[product] > 0:\n",
" inventory[product] -= 1\n",
" else:\n",
" print(f\"Warning: {product} is out of stock!\")\n",
"\n",
"# Step 10: Print updated inventory\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"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 +157,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down