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
152 changes: 150 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,159 @@
"\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": 1,
"id": "d362d7cc",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a111a8c9",
"metadata": {},
"outputs": [],
"source": [
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}s available: \"))\n",
" inventory[product] = quantity \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "8938eeaa",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6873b8ce",
"metadata": {},
"outputs": [],
"source": [
"continue_ordering = \"yes\"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "da39a354",
"metadata": {},
"outputs": [],
"source": [
"while continue_ordering == \"yes\":\n",
" product_name = input(\"Enter the name of a product the customer wants to order: \").strip().lower()\n",
" customer_orders.add(product_name)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "5d3e5a2e",
"metadata": {},
"outputs": [],
"source": [
"continue_ordering = input(\"Do you want to add another product? (yes/no): \").strip().lower()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "a9037dfb",
"metadata": {},
"outputs": [],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "75d37248",
"metadata": {},
"outputs": [],
"source": [
"order_status = (total_products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "6edb35b0",
"metadata": {},
"outputs": [],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ddd48733",
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "91c7d81c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 100\n",
"mug: 200\n",
"hat: 300\n",
"book: 49\n",
"keychain: 10\n"
]
}
],
"source": [
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +203,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.7"
}
},
"nbformat": 4,
Expand Down
Loading