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
56 changes: 54 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,63 @@
"\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": "0b9dd6bc",
"metadata": {},
"outputs": [],
"source": [
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {} \n",
"\n",
"for item in products:\n",
" quantity = int(input(\"Enter the number of product available: \"))\n",
" inventory[item] = quantity\n",
"\n",
"customer_orders = set()\n",
"\n",
"while True:\n",
" product = input(\"Enter the product name: \").lower()\n",
" \n",
" if product in products:\n",
" customer_orders.add(product) \n",
" else:\n",
" print(\"Invalid product. Please choose from:\", products)\n",
" while True:\n",
" add_more = input(\"Do you want to order another product? (yes/no): \").lower()\n",
" if add_more in (\"yes\", \"no\"):\n",
" break\n",
" print(\"Please answer in 'yes' or 'no'.\")\n",
" if add_more == \"no\":\n",
" break\n",
" \n",
"print(\"Products in customer orders:\", 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",
"\n",
"print(\"Order Statistics\")\n",
"print(\"Total Products Ordered:\", order_status[0])\n",
"print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n",
"\n",
"for product_name in customer_orders:\n",
" if product_name in inventory:\n",
" inventory[product_name] -= 1\n",
"\n",
"print(\"Updated Inventory:\")\n",
"for item in products:\n",
" print(f\"{item}, Quantity Left: {inventory[item]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +107,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down