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
77 changes: 75 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"# Lab | Flow Control"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e890486c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
Expand Down Expand Up @@ -37,11 +45,76 @@
"\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": 7,
"id": "011c3ad9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book'}\n",
"Order Statistics:\n",
"Total Products Ordered: 1\n",
"Percentage of Products Ordered: 20.0%\n",
"t-shirt: 25\n",
"mug: 20\n",
"hat: 24\n",
"book: 499\n",
"keychain: 20\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" customer_orders = set()\n",
"\n",
"while True:\n",
" order = input(\"Enter the name of a product to order: \")\n",
" customer_orders.add(order)\n",
" \n",
" another = input(\"Do you want to add another product? (yes/no): \").lower()\n",
" if another != \"yes\":\n",
" break\n",
" \n",
" print(customer_orders)\n",
"\n",
" total_products_ordered = len(customer_orders)\n",
" percentage_ordered = (total_products_ordered / len(products)) * 100\n",
" order_status = (total_products_ordered, percentage_ordered)\n",
" print(\"Order Statistics:\") \n",
" print(f\"Total Products Ordered: {order_status[0]}\")\n",
" print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\") \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f655fb1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "data-analyst",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +128,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down