Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
42 changes: 41 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,46 @@
"\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": "3ace3f95-0633-4b62-8d82-fdcc48e29bdb",
"metadata": {},
"outputs": [],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={} \n",
"\n",
"for x in products:\n",
" qnt =input (f\" Enter the inventory quantity of {x}: \")\n",
" inventory[x] = int(qnt)\n",
" \n",
"customer_orders = set()\n",
"answer=\"yes\"\n",
"\n",
"while answer == \"yes\" : #2-d\n",
" product = input(\"Enter a product (t-shirt, mug, hat, book, keychain): \") #2-a\n",
" if product in products:\n",
" customer_orders.add(product) #2-b\n",
" else:\n",
" print(\"Invalid product. Please enter one of the listed products.\")\n",
" answer = input(\"Do you want to add another product? (yes/no): \") #2-c\n",
"\n",
"for product in customer_orders: #3\n",
" inventory[product] -= 1\n",
" print(product, inventory[product])\n",
" \n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3531d6c1-e445-4b36-9940-ab5ab8738fb3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -55,7 +95,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down