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
84 changes: 82 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,91 @@
"\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": 1,
"id": "5875eb86",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 2}\n"
]
}
],
"source": [
"inventory = {'mug':0, 'hat':0, 'keychain':0, 'book':0, 't-shirt':0}\n",
"\n",
"for item in inventory:\n",
" product = input (\"Enter a value\")\n",
" if product in inventory:\n",
" value = (int(input(\"Enter a value\")))\n",
" inventory[item]=value\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3b41c672",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Availability: {'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 2}\n",
"{'t-shirt'}\n",
"Thanks for your purchase.\n"
]
}
],
"source": [
"customer_orders = set()\n",
"\n",
"continue_buying = \"Yes\"\n",
"\n",
"while continue_buying == \"Yes\":\n",
" print(\"Availability:\", inventory)\n",
" product = input(\"What do you want to buy?: \")\n",
" customer_orders.add(product)\n",
" print(customer_orders)\n",
" continue_buying = input(\"Do you want to continue buying? (Yes/No): \")\n",
" \n",
"print(\"Thanks for your purchase.\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3d84c06d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug': 2, 'hat': 3, 'keychain': 5, 'book': 1, 't-shirt': 1}\n"
]
}
],
"source": [
"customer_orders = {'t-shirt'}\n",
"\n",
"for item in customer_orders:\n",
" if item in inventory:\n",
" inventory[item]-=1\n",
" print(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +135,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down