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
62 changes: 60 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,69 @@
"\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": "f0a0b6e2",
"metadata": {},
"outputs": [],
"source": [
"inventory = {\"t-shirt\": 10,\"pants\": 5,\"shoes\": 3,\"jacket\": 2}\n",
"\n",
"costumers_order = set()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36af25f1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pants added to your order.\n",
"Your order includes the following products: {'pants'}\n",
"\n",
"Inventory after processing the order:\n",
"t-shirt: 10 units left\n",
"pants: 4 units left\n",
"shoes: 3 units left\n",
"jacket: 2 units left\n",
"\n",
"Final inventory status: {'t-shirt': 10, 'pants': 4, 'shoes': 3, 'jacket': 2}\n"
]
}
],
"source": [
"add_product = \"yes\"\n",
"\n",
"while add_product.lower() == \"yes\":\n",
" product = input(f\"Enter the product you want to order(Items available: {list(inventory.keys())}): \").lower()\n",
" if product in inventory:\n",
" costumers_order.add(product)\n",
" print(f\"{product} added to your order.\")\n",
" else:\n",
" print(\"Product not found in inventory.\")\n",
"\n",
" add_product = input(\"Do you want to add another product? (yes/no): \")\n",
"print(f\"Your order includes the following products: {costumers_order}\")\n",
"\n",
"print(\"\\nInventory after processing the order:\")\n",
"for item, quantity in inventory.items():\n",
" if item in costumers_order:\n",
" inventory[item] -= 1 # Assuming one unit of each product is ordered\n",
" print(f\"{item}: {inventory[item]} units left\")\n",
"print(f\"\\nFinal inventory status: {inventory}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +113,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down