Skip to content
Open

lab2 #603

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
47 changes: 45 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,54 @@
"\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": 15,
"id": "57394a05",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory {'t-shirts': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n",
"Customer's unique orders: {'hat', 'mug'}\n",
"Updated inventory: {'t-shirts': 5, 'mug': 4, 'hat': 4, 'book': 5, 'keychain': 5}\n"
]
}
],
"source": [
"products = [\"t-shirts\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for item in products:\n",
" quantity = int(input(f\"Please enter the quantity for {item}: \"))\n",
" inventory[item] = quantity\n",
"\n",
"print(\"Inventory\", inventory)\n",
"\n",
"customers_orders = set()\n",
"\n",
"continue_ordering = \"yes\"\n",
"while continue_ordering == \"yes\":\n",
" order = input(\"Please enter the product you want to order:\" )\n",
" customers_orders.add(order)\n",
"\n",
" continue_ordering = input(\"Do you want to order another product? (yes/no): \")\n",
"\n",
"print(\"Customer's unique orders:\", customers_orders)\n",
"\n",
"for item in customers_orders:\n",
" if item in inventory:\n",
" inventory[item] -= 1\n",
"print(\"Updated inventory:\", inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +98,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down