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
110 changes: 109 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,114 @@
"\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": "05dbb288-0ce4-4b2c-ab9e-e7692b2b1c67",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "054cb3dc-db4b-46d9-bb51-db830ddd6ccf",
"metadata": {},
"outputs": [],
"source": [
"\n",
"products_list=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f92043e8-8da0-44aa-af21-a79c681675d6",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"please enter the name of a product you want to order mug\n",
"Do you want to add another product ? Yes or No no\n"
]
}
],
"source": [
"customers_order = set()\n",
"while True:\n",
" product = input(\"please enter the name of a product you want to order\")\n",
" customers_order.add(product)\n",
" answer = input(\"Do you want to add another product ? Yes or No\")\n",
" if answer.lower ()!= \"yes\" :\n",
" break\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "d3a6c6d2-95c7-49d7-aea8-203de8f30621",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated inventory: {'t-shirt': 31, 'mug': 11, 'hat': 25, 'book': 7, 'keychain': 10}\n"
]
}
],
"source": [
"inventory_dict = {'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7, 'keychain': 10}\n",
"\n",
"for product in customers_order:\n",
" if product in inventory_dict:\n",
" inventory_dict[product] -= 1\n",
" print(\"Updated inventory:\", inventory_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f043c69-2c37-428c-adc7-64818554a24e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "43e8015e-8cfe-4de2-800c-f7a64236a9f1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "23092814-483f-4e6b-b5fa-6a92fe5aee69",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a11c4dbb-5760-4654-b014-38c3c898cec4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd13b6fb-f3fc-4593-a39c-b03b2a28479b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -55,7 +163,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.11"
}
},
"nbformat": 4,
Expand Down