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
127 changes: 124 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,134 @@
"\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": 1,
"id": "863664a2-71ce-4b17-819e-7a1812fd9120",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of t-shirt available in the inventory: 22\n",
"quantity of mug available in the inventory: 34\n",
"quantity of hat available in the inventory: 45\n",
"quantity of book available in the inventory: 65\n",
"quantity of keychain available in the inventory: 76\n"
]
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={}\n",
"inventory[\"t-shirt\"]=int(input(\"quantity of t-shirt available in the inventory: \"))\n",
"inventory[\"mug\"]=int(input(\"quantity of mug available in the inventory: \"))\n",
"inventory[\"hat\"]=int(input(\"quantity of hat available in the inventory: \"))\n",
"inventory[\"book\"]=int(input(\"quantity of book available in the inventory: \"))\n",
"inventory[\"keychain\"]=int(input(\"quantity of keychain available in the inventory: \"))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "65848c54-3545-470f-ab1d-10a5e41641e8",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"input order : hat\n",
"if you want to add another product (yes/no): yes\n",
"input order : book\n",
"if you want to add another product (yes/no): no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'hat'}\n",
"2\n"
]
}
],
"source": [
"\n",
"customer_orders=set() \n",
"add_another_product=\"yes\"\n",
"\n",
"while add_another_product== \"yes\" :\n",
" x=input(\"input order :\")\n",
" customer_orders.add(x)\n",
" add_another_product=input(\"if you want to add another product (yes/no):\")\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_products_ordered=len(customer_orders)\n",
"print(total_products_ordered)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "f4e8f26a-03e9-41fc-bf62-224a7379b382",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 2\n",
"Percentage of Products Ordered: 40.0\n",
"{'t-shirt': 22, 'mug': 34, 'hat': 42, 'book': 62, 'keychain': 76}\n",
"('t-shirt', 22)\n",
"('mug', 34)\n",
"('hat', 42)\n",
"('book', 62)\n",
"('keychain', 76)\n",
"dict_items([('t-shirt', 22), ('mug', 34), ('hat', 42), ('book', 62), ('keychain', 76)])\n"
]
}
],
"source": [
"\n",
"\n",
"percentage_ordered=len(customer_orders)/len(products)*100\n",
"order_status=(total_products_ordered,percentage_ordered)\n",
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered: \"+ str(total_products_ordered))\n",
"print(\"Percentage of Products Ordered: \"+ str(percentage_ordered))\n",
"\n",
"for item in customer_orders:\n",
" inventory[item]=inventory[item]-1\n",
" \n",
"print (inventory)\n",
"\n",
"for item in inventory.items() :\n",
" print(item)\n",
"\n",
"print(inventory.items())\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5b646a5-82b3-4e02-bf21-4a56cd4cc9d9",
"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 +176,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down