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
113 changes: 110 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,120 @@
"\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": 3,
"id": "c2ee1505-3907-48dc-b1ca-fab2808df807",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of the product t-shirt 2\n",
"Enter the quantity of the product mug 2\n",
"Enter the quantity of the product hat 2\n",
"Enter the quantity of the product book 2\n",
"Enter the quantity of the product keychain 2\n"
]
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={}\n",
"for i in products:\n",
" inventory[i]=int(input(f\"Enter the quantity of the product {i}\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8802172-ac92-4b6c-8f85-85287f44ab9d",
"metadata": {},
"outputs": [],
"source": [
"#a.Prompt the user to enter the name of a product that a customer wants to order."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "e429297d-6a0b-4a48-9a2f-982932a2008e",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Type the exact name of the product you would like mug\n",
"Do you want to buy more?: yes/no lkj\n",
"Type the exact name of the product you would like mug\n",
"Do you want to buy more?: yes/no no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug'}\n",
"{'t-shirt': 2, 'mug': 0, 'hat': 2, 'book': 2, 'keychain': 2}\n"
]
}
],
"source": [
"customer_orders=set()\n",
"n=1\n",
"a=0\n",
"while n ==1:\n",
" item=input(\"Type the exact name of the product you would like\")\n",
" if item in products:\n",
" customer_orders.add(item)\n",
" add_item=input(\"Do you want to buy more?: yes/no\")\n",
" if add_item==\"yes\":\n",
" n=1\n",
" elif add_item==\"no\":\n",
" n=2\n",
"\n",
" elif type(item)==str:\n",
" print(\"Enter the product name again, check in case of any typos\")\n",
"print(customer_orders)\n",
"for order in customer_orders:\n",
" inventory[order]-=1\n",
"print(inventory)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ab75f5f-fe41-4c33-afcb-9267a787f10c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f2e622b-c34f-4967-b16e-d0e3943423ab",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b71ccea8-212d-495b-b4be-ee904f4a80ee",
"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 +162,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down