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
38 changes: 37 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,43 @@
" \n",
" d. Continue the loop until the user does not want to add another product.\n",
"\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\")."
"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\").\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity for {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set()\n",
"\n",
"while True:\n",
" product = input(\"Enter a product name: \").lower()\n",
" \n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"Product not available. Please choose from the list.\")\n",
" continue\n",
" \n",
" another = input(\"Do you want to add another product? (yes/no): \").lower()\n",
" if another != \"yes\":\n",
" break\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"total_unique_orders = len(customer_orders)\n",
"percentage_unique_orders = (total_unique_orders / len(products)) * 100\n",
"\n",
"print(f\"Total unique products ordered: {total_unique_orders}\")\n",
"print(f\"Percentage of unique products ordered: {percentage_unique_orders:.2f}%\")\n",
"\n",
"print(\"Customer orders:\", customer_orders)\n",
"\n",
"print(\"Updated inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n"
]
}
],
Expand Down