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
60 changes: 58 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,62 @@
"# Lab | Flow Control"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e1c0625a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer Orders: {'book'}\n",
"\n",
"Updated Inventory:\n",
"t-shirt : 10\n",
"mug : 12\n",
"hat : 15\n",
"book : 19\n",
"keychain : 18\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set()\n",
"\n",
"while True:\n",
" order = input(\"Enter a product you want to order: \")\n",
"\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" else:\n",
" print(\"Product not available.\")\n",
"\n",
" another = input(\"Do you want to add another product? (yes/no): \").lower()\n",
"\n",
" if another != \"yes\":\n",
" break\n",
"\n",
"print(\"Customer Orders:\", customer_orders)\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"print(\"\\nUpdated Inventory:\")\n",
"\n",
"for product, quantity in inventory.items():\n",
" print(product, \":\", quantity)"
]
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
Expand Down Expand Up @@ -41,7 +97,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down