From 7fe3d8aa61307e66e23e0c0b206c7e93881b5a5b Mon Sep 17 00:00:00 2001 From: prodduturisindhurdy Date: Fri, 10 Oct 2025 15:36:19 +0100 Subject: [PATCH 1/3] lab done --- lab-python-functions.ipynb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..a8ba7f5 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,35 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21ffafa9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf29f094", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73b44dd9", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +85,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" } }, "nbformat": 4, From fa587bf9ea119182070cf227b499927bbb98c381 Mon Sep 17 00:00:00 2001 From: prodduturisindhurdy Date: Fri, 10 Oct 2025 15:37:24 +0100 Subject: [PATCH 2/3] lab sloved --- lab-python-functions.ipynb | 205 +++++++++++++++++++++++++++++++++++-- 1 file changed, 197 insertions(+), 8 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index a8ba7f5..24a3359 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,26 +46,215 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "21ffafa9", + "execution_count": 95, + "id": "aed5288b", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", + "inventory={}\n", + "def initalize_inventory(products):\n", + " for product in products:\n", + " user_input=int(input(\"enter the quanity\"))\n", + " inventory[product]=user_input\n", + " \n", + "\n" + ] }, { "cell_type": "code", - "execution_count": null, - "id": "bf29f094", + "execution_count": 96, + "id": "bf722284", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "initalize_inventory(products)" + ] }, { "cell_type": "code", - "execution_count": null, - "id": "73b44dd9", + "execution_count": 97, + "id": "6266cea0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "10a36a48", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders=set()\n", + "def get_customer_orders():\n", + " for i in range(3):\n", + " user_input=input(\"enter the name of the product\")\n", + " customer_orders.add(user_input)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "ef7a8ec9", "metadata": {}, "outputs": [], + "source": [ + "get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "3a02930a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "516a9c4e", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventary(customer_orders,inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product]-=1" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "7d9f031e", + "metadata": {}, + "outputs": [], + "source": [ + "update_inventary(customer_orders,inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "bc7029d7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "68b3d978", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders,products):\n", + " total_products_order=len(customer_orders)\n", + " percentage=(total_products_order / len(products)) * 100\n", + " order_statistics=(total_products_order,percentage)\n", + " return order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "abbad890", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calculate_order_statistics(customer_orders,products)" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "id": "fcca9d9a", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " return order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "f2698e66", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d58b8ff", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}" + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [] } ], From f3b1a15b2fbc5b6fa85bc3ab14aed424cb563d33 Mon Sep 17 00:00:00 2001 From: prodduturisindhurdy Date: Fri, 10 Oct 2025 15:54:51 +0100 Subject: [PATCH 3/3] completed lab --- lab-python-functions.ipynb | 111 ++++++++++++------------------------- 1 file changed, 35 insertions(+), 76 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 24a3359..e546f76 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,36 +46,28 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 135, "id": "aed5288b", "metadata": {}, "outputs": [], "source": [ "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", - "inventory={}\n", - "def initalize_inventory(products):\n", + "\n", + "def initialize_inventory(products):\n", + " inventory={}\n", " for product in products:\n", " user_input=int(input(\"enter the quanity\"))\n", " inventory[product]=user_input\n", + " return inventory\n", " \n", - "\n" + " \n" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 136, "id": "bf722284", "metadata": {}, - "outputs": [], - "source": [ - "initalize_inventory(products)" - ] - }, - { - "cell_type": "code", - "execution_count": 97, - "id": "6266cea0", - "metadata": {}, "outputs": [ { "data": { @@ -83,44 +75,36 @@ "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}" ] }, - "execution_count": 97, + "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "inventory" + "initialize_inventory(products)" ] }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 137, "id": "10a36a48", "metadata": {}, "outputs": [], "source": [ - "customer_orders=set()\n", + "\n", "def get_customer_orders():\n", + " customer_orders=set()\n", " for i in range(3):\n", " user_input=input(\"enter the name of the product\")\n", - " customer_orders.add(user_input)\n" + " customer_orders.add(user_input)\n", + " return customer_orders\n" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 138, "id": "ef7a8ec9", "metadata": {}, - "outputs": [], - "source": [ - "get_customer_orders()" - ] - }, - { - "cell_type": "code", - "execution_count": 100, - "id": "3a02930a", - "metadata": {}, "outputs": [ { "data": { @@ -128,62 +112,53 @@ "{'book', 'hat', 'mug'}" ] }, - "execution_count": 100, + "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "customer_orders" + "get_customer_orders()" ] }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 139, "id": "516a9c4e", "metadata": {}, "outputs": [], "source": [ - "def update_inventary(customer_orders,inventory):\n", + "def update_inventory(customer_orders,inventory):\n", " for product in customer_orders:\n", " if product in inventory:\n", - " inventory[product]-=1" + " inventory[product]-=1\n", + " return inventory" ] }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 140, "id": "7d9f031e", "metadata": {}, - "outputs": [], - "source": [ - "update_inventary(customer_orders,inventory)" - ] - }, - { - "cell_type": "code", - "execution_count": 103, - "id": "bc7029d7", - "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}" + "{'t-shirt': 10, 'mug': 17, 'hat': 27, 'book': 37, 'keychain': 50}" ] }, - "execution_count": 103, + "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "inventory" + "update_inventory(customer_orders,inventory)" ] }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 141, "id": "68b3d978", "metadata": {}, "outputs": [], @@ -197,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 142, "id": "abbad890", "metadata": {}, "outputs": [ @@ -207,7 +182,7 @@ "(3, 60.0)" ] }, - "execution_count": 109, + "execution_count": 142, "metadata": {}, "output_type": "execute_result" } @@ -218,44 +193,28 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 143, "id": "fcca9d9a", "metadata": {}, "outputs": [], "source": [ "def print_order_statistics(order_statistics):\n", - " return order_statistics" + " \n", + " print(f\"Total products ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of unique products ordered: {order_statistics[1]:.2f}%\")" ] }, { "cell_type": "code", - "execution_count": 115, + "execution_count": 144, "id": "f2698e66", "metadata": {}, "outputs": [], "source": [ "def print_updated_inventory(inventory):\n", - " return inventory" + " for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3d58b8ff", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}" - ] - }, - "execution_count": 116, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] } ], "metadata": {