From 6ed2d0bcaccf16bcdb68662827e2ff0b17f2841f Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:12:11 +0100 Subject: [PATCH 1/6] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 120 ++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..5f4f7b6 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,127 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "bf334877", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "customer_orders = set()\n", + "\n", + "inventory = {\"t-shirt\": 10, \"mug\" : 5, \"hat\": 2, \"book\": 0, \"keychain\": 15}" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "640786d3", + "metadata": {}, + "outputs": [], + "source": [ + "# 1\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter a quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + " return inventory " + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "02abdad2", + "metadata": {}, + "outputs": [], + "source": [ + "#2\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " order = input(\"Enter a product to orter\")\n", + " if order == \"exit\":\n", + " break\n", + " else:\n", + " customer_orders.add(order)\n", + " return customer_orders\n", + "\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "45edb707", + "metadata": {}, + "outputs": [], + "source": [ + "# 3\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for order in customer_orders:\n", + " if order in inventory and inventory[order] > 0:\n", + " inventory[order] -=1\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da97a55d", + "metadata": {}, + "outputs": [], + "source": [ + "#4\n", + "\n", + "def calculate_order_statistic (customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage = (total_products_ordered / len(products)) * 100\n", + "\n", + " return total_products_ordered, percentage\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "2b423687", + "metadata": {}, + "outputs": [], + "source": [ + "# 5\n", + "\n", + "def print_order_statistics (order_statistics):\n", + " total_products_ordered, percentage = order_statistics\n", + "\n", + " print(f\"Total products ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of products ordered: {percentage:.2f}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c59886d", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +177,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From d4de9e2fa6bd3bf3ea3dee61a9a3f1356257c932 Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:12:23 +0100 Subject: [PATCH 2/6] Update lab-python-functions.ipynb --- 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 5f4f7b6..dac5eca 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -154,11 +154,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "8c59886d", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#6 \n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\") \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f5567cd", + "metadata": {}, + "outputs": [], + "source": [ + "# 7\n", + "inventory = initialize_inventory (products)\n", + "customer_orders = get_customer_orders()\n", + "updated_inventory = update_inventory (customer_orders, inventory)\n", + "order_statistics = calculate_order_statistic (customer_orders, products)\n", + "print_order_statistics (order_statistics)\n", + "print_updated_inventory (updated_inventory)\n", + "\n" + ] } ], "metadata": { From e32be3f9384644c4cf82a7564f52642d3a27bcdc Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:15:26 +0100 Subject: [PATCH 3/6] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index dac5eca..c83b21e 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -128,7 +128,7 @@ "source": [ "#4\n", "\n", - "def calculate_order_statistic (customer_orders, products):\n", + "def calculate_order_statistics (customer_orders, products):\n", " total_products_ordered = len(customer_orders)\n", " percentage = (total_products_ordered / len(products)) * 100\n", "\n", @@ -178,7 +178,7 @@ "inventory = initialize_inventory (products)\n", "customer_orders = get_customer_orders()\n", "updated_inventory = update_inventory (customer_orders, inventory)\n", - "order_statistics = calculate_order_statistic (customer_orders, products)\n", + "order_statistics = calculate_order_statistics (customer_orders, products)\n", "print_order_statistics (order_statistics)\n", "print_updated_inventory (updated_inventory)\n", "\n" From 2868e38a8e9d98a3c647f7d919d90c7531b8f073 Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:19:13 +0100 Subject: [PATCH 4/6] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index c83b21e..370fa86 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -179,7 +179,7 @@ "customer_orders = get_customer_orders()\n", "updated_inventory = update_inventory (customer_orders, inventory)\n", "order_statistics = calculate_order_statistics (customer_orders, products)\n", - "print_order_statistics (order_statistics)\n", + "print_order_statistics (order_statistics) \n", "print_updated_inventory (updated_inventory)\n", "\n" ] From ea8521e64f9fb31bb51b699439fca90d7a93e754 Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:38:51 +0100 Subject: [PATCH 5/6] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 370fa86..89a7cdc 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "640786d3", "metadata": {}, "outputs": [], @@ -75,12 +75,15 @@ " quantity = int(input(f\"Enter a quantity of {product}: \"))\n", " inventory[product] = quantity\n", "\n", - " return inventory " + " return inventory\n", + "\n", + "\n", + " " ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 35, "id": "02abdad2", "metadata": {}, "outputs": [], @@ -91,7 +94,7 @@ " customer_orders = set()\n", "\n", " while True:\n", - " order = input(\"Enter a product to orter\")\n", + " order = input(\"Enter a product to order or 'exit' to finish: \")\n", " if order == \"exit\":\n", " break\n", " else:\n", @@ -121,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "da97a55d", "metadata": {}, "outputs": [], @@ -138,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 38, "id": "2b423687", "metadata": {}, "outputs": [], @@ -154,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 39, "id": "8c59886d", "metadata": {}, "outputs": [], @@ -169,10 +172,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "id": "3f5567cd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total products ordered: 4\n", + "Percentage of products ordered: 80.00\n", + "Updated Inventory:\n", + "t-shirt: 0\n", + "mug: 2\n", + "hat: 2\n", + "book: 3\n", + "keychain: 4\n" + ] + } + ], "source": [ "# 7\n", "inventory = initialize_inventory (products)\n", From 90cebbb098631d808ea094711b9006bbeca1fc2b Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 16:44:17 +0100 Subject: [PATCH 6/6] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 89a7cdc..f225b8c 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 44, "id": "bf334877", "metadata": {}, "outputs": [], @@ -57,12 +57,12 @@ "\n", "customer_orders = set()\n", "\n", - "inventory = {\"t-shirt\": 10, \"mug\" : 5, \"hat\": 2, \"book\": 0, \"keychain\": 15}" + "inventory = {}" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "id": "640786d3", "metadata": {}, "outputs": [], @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 46, "id": "02abdad2", "metadata": {}, "outputs": [], @@ -107,7 +107,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 47, "id": "45edb707", "metadata": {}, "outputs": [], @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 48, "id": "da97a55d", "metadata": {}, "outputs": [], @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 49, "id": "2b423687", "metadata": {}, "outputs": [], @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 50, "id": "8c59886d", "metadata": {}, "outputs": [], @@ -172,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 51, "id": "3f5567cd", "metadata": {}, "outputs": [ @@ -180,14 +180,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "Total products ordered: 4\n", - "Percentage of products ordered: 80.00\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.00\n", "Updated Inventory:\n", - "t-shirt: 0\n", - "mug: 2\n", - "hat: 2\n", - "book: 3\n", - "keychain: 4\n" + "t-shirt: 5\n", + "mug: 5\n", + "hat: 3\n", + "book: 2\n", + "keychain: 21\n" ] } ],