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
90 changes: 87 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,97 @@
"\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": 6,
"id": "625abbd7-9833-4ab5-92fa-93ec5b8d3dc9",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the name of the product you want to order: plates\n",
"Do you want to continue? (yes/no) yes\n",
"Enter the name of the product you want to order: spoons\n",
"Do you want to continue? (yes/no) yes\n",
"Enter the name of the product you want to order: forks\n",
"Do you want to continue? (yes/no) no\n"
]
},
{
"data": {
"text/plain": [
"{'forks', 'plates', 'spoons'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"customer_orders = set()\n",
"\n",
"keep_adding = \"yes\"\n",
"#Continue the loop until the user does not want to add another product.\n",
"while keep_adding == \"yes\":\n",
"# Prompt the user to enter the name of a product that a customer wants to order.\n",
" product_name = input(\"Enter the name of the product you want to order: \")\n",
"# Add the product to the \"customer_orders\" set.\n",
" customer_orders.add(product_name)\n",
"# Ask the user if they want to add another product (yes/no).\n",
" keep_adding = input(\"Do you want to continue? (yes/no)\")\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "4a765cb7-549e-4d23-83ec-baf9081f3599",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"How many forks would you like to order? 2\n",
"How many plates would you like to order? 2\n",
"How many spoons would you like to order? 2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your total products ordered are: 6\n"
]
}
],
"source": [
"total_products_ordered = 0\n",
"\n",
"for item in customer_orders:\n",
" item_quantity = int(input(f\"How many {item} would you like to order? \"))\n",
" total_products_ordered = total_products_ordered + item_quantity\n",
" \n",
"print(\"Your total products ordered are: \", total_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0733e2fd-02cc-4e85-8a4e-e7f9f4bfa905",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -55,7 +139,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down