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
45 changes: 45 additions & 0 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,51 @@
"# Lab | Flow Control"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"keychain\", \"book\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity available for {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
" customer_orders = set() \n",
"\n",
"# Keep adding products\n",
" while True :\n",
" product = input(\"Enter a product to order : \")\n",
" customer_orders.add(product)\n",
"\n",
" more_product = input(\"Do you want to add more products? (yes/no) :\")\n",
" if more_product.lower() == \"no\" :\n",
" break\n",
" print(\"Customer Orders : \",customer_orders)\n",
"\n",
" # Order Statistics\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(\"Order Statistics:\")\n",
" print(\"Total Products Ordered:\", total_products_ordered)\n",
" print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")\n",
"\n",
" for product in customer_orders :\n",
" inventory[product] -= 1\n",
"\n",
" print(\"Updated Inventory : \") \n",
" for product,quantity in inventory.items():\n",
" print(product \":\" quantity) "
]
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
Expand Down