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
108 changes: 106 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"# Lab | Flow Control"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2951e0b0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
Expand Down Expand Up @@ -37,11 +45,107 @@
"\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": 10,
"id": "aba15676",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"----Place customerr orders---- \n",
"\n",
"final customer Orders:\n",
"{'book'}\n",
"\n",
"final customer Orders:\n",
"{'mug', 'book'}\n",
"\n",
"final customer Orders:\n",
"{'mug', 'book', 'key'}\n",
"\n",
"----Updating inventory----\n"
]
}
],
"source": [
"# Last Product detail from Previous lab\n",
"\n",
"Products = [\"t-shrit\", \"mug\", \"hat\", \"book\", \"key\"]\n",
"\n",
"# Populate initial inventory - for eg , 10 of inventory {}\n",
"\n",
"inventory = {}\n",
"for product in products:\n",
" inventory[product] = 10\n",
"\n",
"#Step 2 initialize an empty Customer orders set \n",
"\n",
"customer_orders = set()\n",
"\n",
"#Step 3 use a while loop to dynamically collect customer orders\n",
"\n",
"print (\"----Place customerr orders---- \")\n",
"\n",
"while True:\n",
" Order_item = input (\" Enter the name of a Product you want to order :\").lower().strip()\n",
"\n",
" #add product name to customer orders set\n",
"\n",
" customer_orders.add(Order_item)\n",
"\n",
" #ask user if they want to place another product (y/n)\n",
" \n",
" user_choice = input (\"Do you want to place another product ? (y/n) :\").lower().strip()\n",
"\n",
" #continue the loop the user does not want to add another product\n",
"\n",
" if user_choice == 'n':\n",
" break\n",
"\n",
" #show final customer orders\n",
"\n",
" print(\"\\nfinal customer Orders:\")\n",
" print(customer_orders)\n",
"\n",
"\n",
"#loop only through products that were actually ordered to update inventory\n",
"\n",
"print(\"\\n----Updating inventory----\")\n",
"for items in customer_orders:\n",
" if items in inventory:\n",
" inventory[items] -= 1\n",
" else:\n",
" print(f\"Note:'{ordered_item}' is not a Product in our store Catalog.\")\n",
"\n",
"\n",
" # print updated inventory to verify.\n",
"\n",
"\n",
" print(\"\\nUpdated Inventory status:\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
" \n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10b78b11",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv (3.14.6.final.0)",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +159,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down