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.
96 changes: 93 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"## Exercise: Managing Customer Orders Optimized\n",
"\n",
Expand All @@ -37,11 +39,99 @@
"\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": 2,
"id": "74ac71c2",
"metadata": {},
"outputs": [],
"source": [
"productsBV = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] "
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "6f50f038",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10, 'mug': 5, 'hat': 15, 'book': 20, 'keychain': 25}\n"
]
}
],
"source": [
"inventoryBV={}\n",
"for pkeys in productsBV:\n",
" inventoryBV[f\"{pkeys}\"]=int(input(f\"enter quantity of product available for {pkeys} in the inventory\"))\n",
" \n",
"print(inventoryBV)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "e5585b2e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"customer order is: {'t-shirt', 'keychain', 'hat', 'book'}\n"
]
}
],
"source": [
"customer_orders=set()\n",
"\n",
"customer_orders.add(input(\"enter the name of a product you want to order between t-shirt, mug, hat, book, keychain\"))\n",
"while input(\"do you want to order another product? (yes/no)\") == \"yes\":\n",
" customer_orders.add(input(\"enter the name of a product you want to order between t-shirt, mug, hat, book, keychain\"))\n",
"else: print(f\"customer order is: {customer_orders}\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "1e9abf9c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 9, 'mug': 5, 'hat': 14, 'book': 19, 'keychain': 24}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for product, inventory in inventoryBV.items():\n",
" if product in customer_orders:\n",
" inventoryBV[product] = inventory - 1\n",
"\n",
"inventoryBV"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9290fbc3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down