Skip to content

flow control lab completed #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
81 changes: 79 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,88 @@
"\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": 26,
"id": "a8884dc7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"for quan_prod in products:\n",
" quantity = int(input(f\"Enter the quantity of {products} available in the inventory:\"))\n",
" inventory[quan_prod] = quantity\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "b87deb1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug'}\n",
"{'hat', 'mug'}\n",
"{'hat', 'mug'}\n"
]
}
],
"source": [
"customer_order = set()\n",
"while True:\n",
" product_name = input(f\"Enter the name of the {products} that a customer wants to order: \")\n",
" customer_order.add(product_name)\n",
" print(customer_order)\n",
"\n",
" add_product = input(\"Do you want to add anoter product(yes, no): \").upper()\n",
" if add_product == \"YES\":\n",
" continue\n",
" elif add_product != \"YES\":\n",
" break\n",
"\n",
"print(customer_order)\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "b43398bd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 1, 'mug': 1, 'hat': 2, 'book': 4, 'keychain': 5}\n"
]
}
],
"source": [
"for prod_order in customer_order:\n",
" inventory[prod_order] -= 1\n",
" \n",
"\n",
"print(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +132,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down