From 93f7550387fcd08a0399992b315fe3302ba222e6 Mon Sep 17 00:00:00 2001 From: Monika Sinha Date: Sun, 8 Mar 2026 12:20:31 +0100 Subject: [PATCH] Solved lab --- lab-python-flow-control.ipynb | 127 +++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..92f171e 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -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": { @@ -55,7 +176,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,