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
66 changes: 64 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,73 @@
"\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": 4,
"id": "41ebb6a5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"list of the products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"Inventory: {'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n",
"Customer orders: {'hat', 'book', 't-shirt'}\n",
"Updated inventory is: \n",
"t-shirt: 0\n",
"mug: 2\n",
"hat: 2\n",
"book: 3\n",
"keychain: 5\n"
]
}
],
"source": [
"#1.\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"print(f\"list of the products: {products}\")\n",
"\n",
"\n",
"inventory = {}\n",
"\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"pleaase enter the quantity of {product}:\"))\n",
" inventory[product] = quantity\n",
"print(f\"Inventory: {inventory}\")\n",
"\n",
"#2.\n",
"customer_orders = set()\n",
"\n",
"\n",
"adding_more = \"yes\" \n",
"\n",
"while adding_more == \"yes\":\n",
" order = input((\"Please enter the product's name that you want to order: \"))\n",
" customer_orders.add(order)\n",
" adding_more = input(\"Add another product? (yes/no): \").lower()\n",
"\n",
"print(f\"Customer orders: {customer_orders}\")\n",
"\n",
"\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
" \n",
"print(\"Updated inventory is: \")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +117,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down