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
107 changes: 105 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,114 @@
"\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": "d63c115e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"source": [
"#1.\n",
"\n",
"products = (\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\")\n",
"\n",
"print(len(products))\n",
"inventory = { }\n",
"\n",
"\n",
"for f in products:\n",
" inventory[f] = int(input('Quantity of products:'))\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "a58928ca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 43, 'mug': 42, 'hat': 21, 'book': 10, 'keychain': 34}\n"
]
}
],
"source": [
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "2215899e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thanks for purchase\n",
"{'book', 'hat'}\n"
]
}
],
"source": [
"#2. \n",
"customer_orders = set()\n",
"\n",
"continue_ordering = 'Yes'\n",
"\n",
"while continue_ordering == 'Yes':\n",
" product_name = input('Enter the Name of Product:' )\n",
" if product_name in inventory:\n",
" customer_orders.add(product_name)\n",
" else:\n",
" continue_ordering= input('Do you want to continue order (yes/no):')\n",
" \n",
"print('Thanks for purchase')\n",
"print(customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "5e67910d",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "'set' object is not subscriptable",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[20]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m#3. \u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m subt \u001b[38;5;129;01min\u001b[39;00m customer_orders:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m customer_orders[subt] = \u001b[43mcustomer_orders\u001b[49m\u001b[43m[\u001b[49m\u001b[43msubt\u001b[49m\u001b[43m]\u001b[49m -\u001b[32m1\u001b[39m\n",
"\u001b[31mTypeError\u001b[39m: 'set' object is not subscriptable"
]
}
],
"source": [
"#3. \n",
"\n",
"for subt in customer_orders:\n",
" customer_orders[subt] = customer_orders[subt] -1\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.2"
}
},
"nbformat": 4,
Expand Down