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
66 changes: 66 additions & 0 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,72 @@
"\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": "5e832c33",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# 1.\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# 2.\n",
"inventory = {}\n",
"\n",
"# 3.\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product} available in inventory: \"))\n",
" inventory[product] = quantity\n",
"\n",
"# 4.\n",
"customer_orders = set()\n",
"\n",
"# 5.\n",
"while True:\n",
" order = input(\"Enter the name of a product to order (t-shirt, mug, hat, book, keychain): \").strip().lower()\n",
" \n",
" if order in products:\n",
" customer_orders.add(order)\n",
" print(f\"{order} added to your order.\")\n",
" else:\n",
" print(f\"Invalid product. Please choose from: {', '.join(products)}\")\n",
" continue\n",
" \n",
" another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n",
" if another != \"yes\":\n",
" break\n",
"\n",
"# 6.\n",
"print(\"Customer Orders:\", customer_orders)\n",
"\n",
"# 7.\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",
"# 8.\n",
"print(f\"\"\"\n",
"Order Statistics:\n",
"Total Products Ordered: {order_status[0]}\n",
"Percentage of Products Ordered: {order_status[1]:.2f}%\n",
"\"\"\")\n",
"\n",
"# 9.\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"# 10.\n",
"print(\"Updated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
Expand Down