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
78 changes: 76 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,85 @@
"\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": 7,
"id": "68d0b580",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 8, 'hat': 3, 'book': 12, 'keychain': 7}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for item in products:\n",
" quantity = int(input(f\"Enter the quantity of {item} in inventory: \"))\n",
" inventory[item] = quantity\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f467e6f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'keychain', 'mug'}\n"
]
}
],
"source": [
"customer_orders = set()\n",
"\n",
"continue_entering = 'yes'\n",
"while continue_entering.lower() == 'yes':\n",
" product_order = input('Enter the product you want to order: ')\n",
" customer_orders.add(product_order)\n",
"\n",
" continue_entering = input('Do you want to add another product? (yes/no)').lower()\n",
"\n",
"print(customer_orders) "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "1d068c62",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 7, 'hat': 3, 'book': 11, 'keychain': 6}\n"
]
}
],
"source": [
"for item in inventory:\n",
" if item in customer_orders:\n",
" inventory[item] -=1\n",
"\n",
"print(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down