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
114 changes: 111 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,121 @@
"\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": 26,
"id": "85fe41a6-9d5f-4b9c-ae45-4986175ef6e0",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter quantity for t-shirt 5\n",
"Enter quantity for mug 6\n",
"Enter quantity for hat 7\n",
"Enter quantity for book 4\n",
"Enter quantity for keychain 6\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 4, 'keychain': 6}\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter product you would like to order: hat\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat'}\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Would you like to order another product? yes\n",
"What product would you like from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'mug'}\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Would you like to order another product? no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 5, 'hat': 6, 'book': 4, 'keychain': 6}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for i in products: \n",
" quantity = int(input(f\"Enter quantity for {i}\"))\n",
" inventory[i] = quantity\n",
"\n",
"print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"order = input(f\"Enter product you would like to order: \")\n",
"customer_orders.add(order)\n",
"print(customer_orders)\n",
"\n",
"while True:\n",
" extra_order = input(\"Would you like to order another product?\").lower()\n",
" if extra_order == \"yes\":\n",
" product2 = input(f\"What product would you like from {products}\")\n",
" else:\n",
" break\n",
" customer_orders.add(product2)\n",
" print(customer_orders)\n",
"\n",
"\n",
"for item in customer_orders:\n",
" inventory[item] = inventory[item] - 1\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ce55b9d-85b9-41ee-9d69-7fdca37fedc1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -55,7 +163,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down