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
123 changes: 121 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,130 @@
"\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": 12,
"id": "af4c676c",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity of {[product]}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "fa28dca9",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()\n",
"\n",
"while True:\n",
" product_order = input(\"Which product do you want to order?: \").lower()\n",
" customer_orders.add(product_order)\n",
" answer = input(\"Do you want to order another product? yes/no: \").lower()\n",
" if answer != \"yes\":\n",
" break\n",
"\n",
" \n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "b256bc36",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10, 'mug': 9, 'hat': 8, 'book': 10, 'keychain': 10}\n"
]
}
],
"source": [
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"print(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7a94670",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1a1382d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3385caf7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "080202a6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "de1ad654",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "778f53d4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "97e13ff2",
"metadata": {},
"outputs": [],
"source": [
" \n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +174,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down