From 83d5a5de3cbab089ec33d67bb605d53bcec5a86a Mon Sep 17 00:00:00 2001 From: baharmnb Date: Sat, 7 Mar 2026 17:13:18 +0100 Subject: [PATCH] solved lab --- .DS_Store | Bin 0 -> 6148 bytes lab-python-functions.ipynb | 156 ++++++++++++++++++++++++++++++++++++- 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ddfc64971d55c349ee8f76c809465931362ff02a GIT binary patch literal 6148 zcmeHK!AitH41LiaR=n&*5JBh8J_Th4Ia>8&D9;Y#3e0_S)Q4%u{~?lyE)~EnO?u-Jirwe zn4!WYvA`o%gNW0?DeNerf`MQl7zhS}fgdx#nyoT9bPOE~1OvgqCj)vv695);) ty06y>g>x&#L@UKy=sj|5PWR_Jr@u_tJ8BlSTR1U(1dNbS!N4yt@D5e=IZprp literal 0 HcmV?d00001 diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..d16bb22 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,160 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "e8947610-da2c-447b-9a68-bd32b4d9bce7", + "metadata": {}, + "outputs": [], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory={} \n", + "def initialize_inventory(products): #1\n", + " \n", + "\n", + " for x in products: \n", + " qnt =input (f\" Enter the inventory quantity of {x}: \")\n", + " inventory[x] = int(qnt)\n", + " return inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "3c8b1d6f-38e0-4dab-b2c5-d3d12adf8f29", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()\n", + "def get_customer_orders(): #2\n", + " \n", + " answer=\"yes\"\n", + "\n", + " while answer == \"yes\" : \n", + " product = input(\"Enter a product (t-shirt, mug, hat, book, keychain): \") \n", + " customer_orders.add(product) \n", + " answer = input(\"Do you want to add another product? (yes/no): \") \n", + " return customer_orders\n" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "f016781a-56b1-436f-be04-92bacd2b4e13", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders,inventory): #3\n", + " for product in customer_orders: \n", + " inventory[product] -= 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "4a9bc856-f567-4798-ba68-3e204e44e543", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics (customer_orders,products): #4\n", + " \n", + " total_products_ordered = len(customer_orders) \n", + " percentage_products_ordered = (total_products_ordered / len(products)) * 100 \n", + " order_statistics = (total_products_ordered, percentage_products_ordered)\n", + " return order_statistics\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "c733cf1b-8ff8-41d1-93d3-5a3821b7e30e", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics): #5\n", + " total, percentage = order_statistics\n", + " print(\"Order Statistics:\") \n", + " print(f\"Total Products Ordered: {total}\")\n", + " print(f\"Percentage of Products Ordered: {percentage}%\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "5f9f6ca4-88b5-451f-b85d-5a54ed33dfc0", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory): #6\n", + " return inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "db8d6253-88ef-41b2-9609-6895f9b54224", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + " Enter the inventory quantity of t-shirt: 8\n", + " Enter the inventory quantity of mug: 9\n", + " Enter the inventory quantity of hat: 45\n", + " Enter the inventory quantity of book: 76\n", + " Enter the inventory quantity of keychain: 4\n", + "Enter a product (t-shirt, mug, hat, book, keychain): hat\n", + "Do you want to add another product? (yes/no): yes\n", + "Enter a product (t-shirt, mug, hat, book, keychain): book\n", + "Do you want to add another product? (yes/no): yes\n", + "Enter a product (t-shirt, mug, hat, book, keychain): mug\n", + "Do you want to add another product? (yes/no): np\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + }, + { + "ename": "NameError", + "evalue": "name 'inventor' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[40], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m order_statistics \u001b[38;5;241m=\u001b[39m calculate_order_statistics (customer_orders,products)\n\u001b[1;32m 6\u001b[0m print_order_statistics(order_statistics)\n\u001b[0;32m----> 7\u001b[0m \u001b[43mprint_updated_inventory\u001b[49m\u001b[43m(\u001b[49m\u001b[43minventory\u001b[49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[0;32mIn[38], line 2\u001b[0m, in \u001b[0;36mprint_updated_inventory\u001b[0;34m(inventory)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mprint_updated_inventory\u001b[39m(inventory): \u001b[38;5;66;03m#6\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43minventor\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'inventor' is not defined" + ] + } + ], + "source": [ + "initialize_inventory(products)\n", + "get_customer_orders()\n", + "update_inventory(customer_orders,inventory)\n", + "calculate_order_statistics (customer_orders,products)\n", + "order_statistics = calculate_order_statistics (customer_orders,products)\n", + "print_order_statistics(order_statistics)\n", + "print_updated_inventory(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2e5abf70-0746-42e7-b2cd-832f420b4a52", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -61,7 +215,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.6" } }, "nbformat": 4,