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
86 changes: 84 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,93 @@
"\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": 2,
"id": "6ddd038c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter available quantity for each product:\n",
"\n",
"Customer ordered the following products:\n",
"- mug\n",
"\n",
"Order Statistics:\n",
"Total Products Ordered: 1\n",
"Percentage of Products Ordered: 20.00%\n",
"\n",
"Updating inventory...\n",
"\n",
"Updated Inventory:\n",
"T-shirt: 3\n",
"Mug: 1\n",
"Hat: 4\n",
"Book: 3\n",
"Keychain: 4\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"print(\"Enter available quantity for each product:\")\n",
"for product in products:\n",
" quantity = int(input(f\"{product.capitalize()}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set()\n",
"\n",
"while True:\n",
" order = input(\"\\nEnter a product to order: \").strip().lower()\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" else:\n",
" print(\"That product is not in the list. Please choose from:\", \", \".join(products))\n",
" \n",
" another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n",
" if another != \"yes\":\n",
" break\n",
"\n",
"\n",
"print(\"\\nCustomer ordered the following products:\")\n",
"for item in customer_orders:\n",
" print(\"-\", item)\n",
"\n",
"\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",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n",
"\n",
"\n",
"print(\"\\nUpdating inventory...\")\n",
"for item in customer_orders:\n",
" if item in inventory and inventory[item] > 0:\n",
" inventory[item] -= 1\n",
" elif item in inventory:\n",
" print(f\"No stock left for {item}.\")\n",
" else:\n",
" print(f\"{item} is not in inventory.\")\n",
"\n",
"\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product in products:\n",
" print(f\"{product.capitalize()}: {inventory[product]}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +137,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down