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
39 changes: 36 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,46 @@
"\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": "645de7a2-8872-45de-ac02-4c9335f28ab6",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" qty = int(input(f\"Enter # of {product}: \"))\n",
" inventory[product] = qty\n",
"\n",
"customer_orders = set()\n",
"\n",
"add_another = \"yes\"\n",
"\n",
"while add_another==\"yes\":\n",
" product_name = input(\"Enter the name of a product that a customer wants: \")\n",
" customer_orders.add(product_name)\n",
"\n",
" add_another = input(\"Do you want to continue to order products? (yes/no)\")\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -=1\n",
"\n",
" print(\"products in customer orders: \", customer_orders)\n",
"\n",
" print(\"Updated inventory: \", inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -55,7 +88,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down