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
49 changes: 49 additions & 0 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,55 @@
"\n",
"3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7723426d",
"metadata": {},
"outputs": [],
"source": [
"\n",
"products = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity for {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set() \n",
"while True:\n",
" product_name = input(\"Enter a product to order: \")\n",
" \n",
" if product_name not in products:\n",
" print(\"Sorry, we don't have that product. Try again.\")\n",
" continue\n",
" \n",
" customer_orders.add(product_name)\n",
" \n",
" another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n",
" if another != \"yes\":\n",
" break\n",
"\n",
" print(\"\\nCustomer Orders:\")\n",
"for item in customer_orders:\n",
" print(item)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {total_products_ordered}\")\n",
"print(f\"Percentage of Products Ordered: {percentage_ordered}%\")\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1 \n",
"\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n"
]
}
],
"metadata": {
Expand Down