From fd6af7020b16dfafa6c944edd82ed30a318b765a Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 15:49:57 +0200 Subject: [PATCH 01/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..61ffc582 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,38 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Inventory = { }\n", + "quantity_input = input(\"Enter the quantity for {'t-shirt'}: \")\n", + "quantity_input = input(\"Enter the quantity for {'mug'}: \")\n", + "quantity_input = input(\"Enter the quantity for {'hat'}: \")\n", + "quantity_input = input(\"Enter the quantity for {'book'}: \")\n", + "quantity_input = input(\"Enter the quantity for {'keychain'}: \")\n", + "inventory[product] = int(quantity_input)\n", + "print(inventory)\n", + "customer_orders = ()\n", + "customer_orders = ('mug', 'hat', 'book')\n", + "Print ('customer_orders')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +95,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From ea094f1920001b19e9bc1eeac3786a2acab3e1c1 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 17:01:38 +0200 Subject: [PATCH 02/28] Update lab-python-data-structures.ipynb nn --- lab-python-data-structures.ipynb | 41 ++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 61ffc582..add7eb87 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -55,20 +55,41 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (3858482429.py, line 3)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mquantity_input = input(for product in products:\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], "source": [ "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - "Inventory = { }\n", - "quantity_input = input(\"Enter the quantity for {'t-shirt'}: \")\n", - "quantity_input = input(\"Enter the quantity for {'mug'}: \")\n", - "quantity_input = input(\"Enter the quantity for {'hat'}: \")\n", - "quantity_input = input(\"Enter the quantity for {'book'}: \")\n", - "quantity_input = input(\"Enter the quantity for {'keychain'}: \")\n", - "inventory[product] = int(quantity_input)\n", + "inventory = { }\n", + "quantity_input = input(for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {'t-shirt'}: \")\n", + "quantity_input = input(for product in products:\n", + " quantity = int(input(f\"Enter the quantity for{'mug'}: \")\n", + "quantity_input = input(for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {'hat'}: \")\n", + "quantity_input = input(for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {'book'}: \")\n", + "quantity_input = input(for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {'keychain'}: \")\n", + "inventory[product] = quantity\n", "print(inventory)\n", - "customer_orders = ()\n", + "customer_orders = set()\n", "customer_orders = ('mug', 'hat', 'book')\n", - "Print ('customer_orders')\n" + "print ('customer_orders')\n", + " int = len(customer_orders)\n", + "total_available: int = len(product_catalog)\n", + " order_percentage: float = (total_ordered / total_available) * 100\n", + " return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", + "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", + "results = calculate_order_stats(customer_orders)\n", + "print(results)" ] }, { From 9eae07935d0b220108e71afe689cec3f39505b42 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 17:15:02 +0200 Subject: [PATCH 03/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 35 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index add7eb87..ebbc444e 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,39 +57,44 @@ "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (3858482429.py, line 3)", + "ename": "IndentationError", + "evalue": "unexpected indent (3022031914.py, line 14)", "output_type": "error", "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mquantity_input = input(for product in products:\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 14\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mint = len(customer_orders)\u001b[39m\n ^\n\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m unexpected indent\n" ] } ], "source": [ "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", - "quantity_input = input(for product in products:\n", - " quantity = int(input(f\"Enter the quantity for {'t-shirt'}: \")\n", - "quantity_input = input(for product in products:\n", - " quantity = int(input(f\"Enter the quantity for{'mug'}: \")\n", - "quantity_input = input(for product in products:\n", - " quantity = int(input(f\"Enter the quantity for {'hat'}: \")\n", - "quantity_input = input(for product in products:\n", - " quantity = int(input(f\"Enter the quantity for {'book'}: \")\n", - "quantity_input = input(for product in products:\n", - " quantity = int(input(f\"Enter the quantity for {'keychain'}: \")\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {'t-shirt'}: \"))\n", + " quantity = int(input(f\"Enter the quantity for {'mug'}: \"))\n", + " quantity = int(input(f\"Enter the quantity for {'hat'}: \"))\n", + " quantity = int(input(f\"Enter the quantity for {'book'}: \"))\n", + " quantity = int(input(f\"Enter the quantity for {'keychain'}: \"))\n", "inventory[product] = quantity\n", "print(inventory)\n", "customer_orders = set()\n", "customer_orders = ('mug', 'hat', 'book')\n", "print ('customer_orders')\n", " int = len(customer_orders)\n", - "total_available: int = len(product_catalog)\n", + "total_available: int = len(list_products)\n", " order_percentage: float = (total_ordered / total_available) * 100\n", " return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", "results = calculate_order_stats(customer_orders)\n", - "print(results)" + "print(results)\n", + "inventory = { }\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity - 1 for {'t-shirt'}: \"))\n", + " quantity = int(input(f\"Enter the quantity - 1 for {'mug'}: \"))\n", + " quantity = int(input(f\"Enter the quantity - 1 for {'hat'}: \"))\n", + " quantity = int(input(f\"Enter the quantity - 1 for {'book'}: \"))\n", + " quantity = int(input(f\"Enter the quantity - 1 for {'keychain'}: \"))\n", + "inventory[product] = quantity\n", + "print(inventory)" ] }, { From b53e6aba2d9da6936c88abea283f733109ec0c09 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 17:29:45 +0200 Subject: [PATCH 04/28] Update lab-python-data-structures.ipynb nn --- lab-python-data-structures.ipynb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index ebbc444e..cf599fb0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,22 +53,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [ { - "ename": "IndentationError", - "evalue": "unexpected indent (3022031914.py, line 14)", + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: ''", "output_type": "error", "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 14\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mint = len(customer_orders)\u001b[39m\n ^\n\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m unexpected indent\n" + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[33;43m'\u001b[39;49m\u001b[33;43mt-shirt\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m quantity = \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mEnter the quantity for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m: \u001b[39m\u001b[33m\"\u001b[39m))\n\u001b[32m 6\u001b[39m quantity = \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mEnter the quantity for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m: \u001b[39m\u001b[33m\"\u001b[39m))\n", + "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" ] } ], "source": [ "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", - "for product in products:\n", + "for product in list_products:\n", " quantity = int(input(f\"Enter the quantity for {'t-shirt'}: \"))\n", " quantity = int(input(f\"Enter the quantity for {'mug'}: \"))\n", " quantity = int(input(f\"Enter the quantity for {'hat'}: \"))\n", @@ -77,17 +80,17 @@ "inventory[product] = quantity\n", "print(inventory)\n", "customer_orders = set()\n", - "customer_orders = ('mug', 'hat', 'book')\n", + "customer_orders = set('mug', 'hat', 'book')\n", "print ('customer_orders')\n", - " int = len(customer_orders)\n", + "int = len(customer_orders)\n", "total_available: int = len(list_products)\n", - " order_percentage: float = (total_ordered / total_available) * 100\n", - " return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", + "order_percentage: float = (total_ordered / total_available) * 100\n", + "return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", "results = calculate_order_stats(customer_orders)\n", "print(results)\n", "inventory = { }\n", - "for product in products:\n", + "for product in list_products:\n", " quantity = int(input(f\"Enter the quantity - 1 for {'t-shirt'}: \"))\n", " quantity = int(input(f\"Enter the quantity - 1 for {'mug'}: \"))\n", " quantity = int(input(f\"Enter the quantity - 1 for {'hat'}: \"))\n", From 7317bb5cd6afe3223a22bb733d21e9d759a4e7f2 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 18:00:28 +0200 Subject: [PATCH 05/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index cf599fb0..937354a7 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -63,7 +63,7 @@ "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[33;43m'\u001b[39;49m\u001b[33;43mt-shirt\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m quantity = \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mEnter the quantity for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m: \u001b[39m\u001b[33m\"\u001b[39m))\n\u001b[32m 6\u001b[39m quantity = \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mEnter the quantity for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m: \u001b[39m\u001b[33m\"\u001b[39m))\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m product_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" ] } @@ -72,16 +72,16 @@ "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", "for product in list_products:\n", - " quantity = int(input(f\"Enter the quantity for {'t-shirt'}: \"))\n", - " quantity = int(input(f\"Enter the quantity for {'mug'}: \"))\n", - " quantity = int(input(f\"Enter the quantity for {'hat'}: \"))\n", - " quantity = int(input(f\"Enter the quantity for {'book'}: \"))\n", - " quantity = int(input(f\"Enter the quantity for {'keychain'}: \"))\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", "inventory[product] = quantity\n", - "print(inventory)\n", - "customer_orders = set()\n", - "customer_orders = set('mug', 'hat', 'book')\n", - "print ('customer_orders')\n", + "\n", + "product_list: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", + "user_input: str = input(\"Enter three products separated by commas (e.g., mug, hat, book): \")\n", + "customer_orders: set[str] = {name.strip().lower() for name in user_input.split(\",\")}\n", + "valid_orders: set[str] = customer_orders.intersection(product_catalog)\n", + "print(f\"Total Products Ordered: {len(valid_orders)}\")\n", + "print(f\"Products in Order: {valid_orders}\")\n", + "\n", "int = len(customer_orders)\n", "total_available: int = len(list_products)\n", "order_percentage: float = (total_ordered / total_available) * 100\n", @@ -89,14 +89,12 @@ "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", "results = calculate_order_stats(customer_orders)\n", "print(results)\n", + "\n", + "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", "for product in list_products:\n", - " quantity = int(input(f\"Enter the quantity - 1 for {'t-shirt'}: \"))\n", - " quantity = int(input(f\"Enter the quantity - 1 for {'mug'}: \"))\n", - " quantity = int(input(f\"Enter the quantity - 1 for {'hat'}: \"))\n", - " quantity = int(input(f\"Enter the quantity - 1 for {'book'}: \"))\n", - " quantity = int(input(f\"Enter the quantity - 1 for {'keychain'}: \"))\n", - "inventory[product] = quantity\n", + " quantity = int(input(f\"Enter the quantity for {product} - 1: \"))\n", + " inventory[product] = quantity\n", "print(inventory)" ] }, From c1e2dfaffd41e8e961f296bceb1f0595671d9a38 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 18:17:45 +0200 Subject: [PATCH 06/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 937354a7..53a6bca1 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -63,7 +63,7 @@ "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m product_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[22]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m product_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" ] } @@ -73,29 +73,25 @@ "inventory = { }\n", "for product in list_products:\n", " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", - "inventory[product] = quantity\n", + " inventory[product] = quantity\n", "\n", "product_list: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", "user_input: str = input(\"Enter three products separated by commas (e.g., mug, hat, book): \")\n", "customer_orders: set[str] = {name.strip().lower() for name in user_input.split(\",\")}\n", - "valid_orders: set[str] = customer_orders.intersection(product_catalog)\n", + "valid_orders: set[str] = customer_orders.intersection(product_list)\n", "print(f\"Total Products Ordered: {len(valid_orders)}\")\n", "print(f\"Products in Order: {valid_orders}\")\n", "\n", - "int = len(customer_orders)\n", - "total_available: int = len(list_products)\n", + "\n", "order_percentage: float = (total_ordered / total_available) * 100\n", "return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", "results = calculate_order_stats(customer_orders)\n", "print(results)\n", "\n", - "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - "inventory = { }\n", - "for product in list_products:\n", - " quantity = int(input(f\"Enter the quantity for {product} - 1: \"))\n", - " inventory[product] = quantity\n", - "print(inventory)" + "for product in inventory:\n", + " inventory[product] -= 1\n", + "print(\"Updated Inventory:\")" ] }, { From 4e6d22b9fc48e1f0a2f5ecd3d2bbc7e74152efaa Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 18:31:18 +0200 Subject: [PATCH 07/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 53a6bca1..c2ce2c01 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -63,32 +63,37 @@ "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[22]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m list_products:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m product_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[27]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m products_list:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m products_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" ] } ], "source": [ - "list_products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", - "for product in list_products:\n", + "for product in products_list:\n", " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", " inventory[product] = quantity\n", "\n", - "product_list: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", + "products_list: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", "user_input: str = input(\"Enter three products separated by commas (e.g., mug, hat, book): \")\n", "customer_orders: set[str] = {name.strip().lower() for name in user_input.split(\",\")}\n", - "valid_orders: set[str] = customer_orders.intersection(product_list)\n", + "valid_orders: set[str] = customer_orders.intersection(products_list)\n", "print(f\"Total Products Ordered: {len(valid_orders)}\")\n", "print(f\"Products in Order: {valid_orders}\")\n", "\n", "\n", - "order_percentage: float = (total_ordered / total_available) * 100\n", - "return f\"Order Statistics: Total Products: {total_ordered}, Percentage: {order_percentage}%\"\n", - "customer_orders: set[str] = {\"mug\", \"hat\", \"book\"}\n", - "results = calculate_order_stats(customer_orders)\n", - "print(results)\n", + "total_ordered = customer_orders\n", + "total_available = products_list\n", + "percentage: float = (total_ordered / total_available) * 100\n", + "print(f\"Total Products Ordered: {total_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage}%\")\n", "\n", + "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "inventory = { }\n", + "for product in products_list:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", "for product in inventory:\n", " inventory[product] -= 1\n", "print(\"Updated Inventory:\")" From 4ad034902fee037496a88a6bbcd148a81bc1c86c Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Mon, 13 Apr 2026 18:38:20 +0200 Subject: [PATCH 08/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index c2ce2c01..c7015833 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -75,7 +75,7 @@ " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", " inventory[product] = quantity\n", "\n", - "products_list: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", + "products: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", "user_input: str = input(\"Enter three products separated by commas (e.g., mug, hat, book): \")\n", "customer_orders: set[str] = {name.strip().lower() for name in user_input.split(\",\")}\n", "valid_orders: set[str] = customer_orders.intersection(products_list)\n", @@ -83,8 +83,8 @@ "print(f\"Products in Order: {valid_orders}\")\n", "\n", "\n", - "total_ordered = customer_orders\n", - "total_available = products_list\n", + "total_ordered: int = len(customer_orders)\n", + "total_available: int = len(products_list)\n", "percentage: float = (total_ordered / total_available) * 100\n", "print(f\"Total Products Ordered: {total_ordered}\")\n", "print(f\"Percentage of Products Ordered: {percentage}%\")\n", From 753b5e2c9168f9e3206e6ba83c92d55f13315da6 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 14:58:37 +0200 Subject: [PATCH 09/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 63 +++++++++++++++++++------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index c7015833..74791fec 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,14 +57,11 @@ "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "invalid literal for int() with base 10: ''", - "output_type": "error", - "traceback": [ - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", - "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[27]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 2\u001b[39m inventory = { }\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m products_list:\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mEnter the quantity for \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mproduct\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m: \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5\u001b[39m inventory[product] = quantity\n\u001b[32m 7\u001b[39m products_list: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = {\u001b[33m\"\u001b[39m\u001b[33mt-shirt\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmug\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mhat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbook\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mkeychain\u001b[39m\u001b[33m\"\u001b[39m}\n", - "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter a valid integer.\n", + " is not a valid choice and will not be added.\n" ] } ], @@ -72,31 +69,45 @@ "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "inventory = { }\n", "for product in products_list:\n", - " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", - " inventory[product] = quantity\n", - "\n", - "products: set[str] = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", - "user_input: str = input(\"Enter three products separated by commas (e.g., mug, hat, book): \")\n", - "customer_orders: set[str] = {name.strip().lower() for name in user_input.split(\",\")}\n", - "valid_orders: set[str] = customer_orders.intersection(products_list)\n", - "print(f\"Total Products Ordered: {len(valid_orders)}\")\n", - "print(f\"Products in Order: {valid_orders}\")\n", - "\n", + " while True:\n", + " quantity_input = input(f\"Enter the quantity for {product}: \") or '0'\n", + " try:\n", + " quantity = int(quantity_input)\n", + " inventory[product] = quantity\n", + " break\n", + " except ValueError:\n", + " print(\"Please enter a valid integer.\")\n", + "customer_orders = set()\n", + "for i in range(3):\n", + " product = input(f\"Enter product {i+1} (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", + " if product in products_list:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(f\"{product} is not a valid choice and will not be added.\")\n", + "print(\"Products in Order:\", customer_orders)\n", "\n", "total_ordered: int = len(customer_orders)\n", "total_available: int = len(products_list)\n", "percentage: float = (total_ordered / total_available) * 100\n", - "print(f\"Total Products Ordered: {total_ordered}\")\n", - "print(f\"Percentage of Products Ordered: {percentage}%\")\n", + "print(f\"total Products Ordered: {total_ordered}\")\n", + "print(f\"percentage of Products Ordered: {percentage}%\")\n", "\n", - "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - "inventory = { }\n", + "order_status = (total products ordered, percentage ordered)\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain'] \n", + "inventory = { } \n", "for product in products_list:\n", " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", " inventory[product] = quantity\n", - "for product in inventory:\n", + " for product in inventory:\n", " inventory[product] -= 1\n", - "print(\"Updated Inventory:\")" + " print(\"Updated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" ] }, { @@ -104,7 +115,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "\n" + ] } ], "metadata": { From d28ea5ef987761660fbd2dea1420a7ae3cfd9ccc Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 15:14:00 +0200 Subject: [PATCH 10/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 74791fec..97548ff2 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -84,19 +84,19 @@ " customer_orders.add(product)\n", " else:\n", " print(f\"{product} is not a valid choice and will not be added.\")\n", - "print(\"Products in Order:\", customer_orders)\n", + "print(\"products in order:\", customer_orders)\n", "\n", "total_ordered: int = len(customer_orders)\n", "total_available: int = len(products_list)\n", "percentage: float = (total_ordered / total_available) * 100\n", - "print(f\"total Products Ordered: {total_ordered}\")\n", - "print(f\"percentage of Products Ordered: {percentage}%\")\n", + "print(f\"total products ordered: {total_ordered}\")\n", + "print(f\"percentage of products ordered: {percentage}%\")\n", "\n", - "order_status = (total products ordered, percentage ordered)\n", + "order_status = ('total products ordered', 'percentage ordered')\n", "\n", - "print(\"\\nOrder Statistics:\")\n", - "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "print(\"\\norder Statistics:\")\n", + "print(f\"Total products ordered: {order_status[0]}\")\n", + "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", "\n", "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain'] \n", "inventory = { } \n", From 29f21ee638e3cd5a547f2f3c382ff6078753c057 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 15:37:33 +0200 Subject: [PATCH 11/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 97548ff2..f9eb2bf8 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -78,12 +78,22 @@ " except ValueError:\n", " print(\"Please enter a valid integer.\")\n", "customer_orders = set()\n", - "for i in range(3):\n", + "for i in range(4):\n", " product = input(f\"Enter product {i+1} (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", " if product in products_list:\n", " customer_orders.add(product)\n", " else:\n", " print(f\"{product} is not a valid choice and will not be added.\")\n", + " while:\n", + " product = input(f'Enter yes to add {product} to the order or no to skip: ').strip().lower() add_product = input(\"Enter yes to add the product to the order or no to skip: \").strip().lower()\n", + " if add_product == 'yes':\n", + " customer_orders.add(product)\n", + " print(f\"{product} has been added to the order.\")\n", + " break\n", + " elif add_product == 'no':\n", + " print(f\"{product} will not be added to the order.\")\n", + " break\n", + " else:\n", "print(\"products in order:\", customer_orders)\n", "\n", "total_ordered: int = len(customer_orders)\n", @@ -99,14 +109,14 @@ "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", "\n", "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain'] \n", - "inventory = { } \n", + "customer_orders = set() \n", "for product in products_list:\n", " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", - " inventory[product] = quantity\n", - " for product in inventory:\n", - " inventory[product] -= 1\n", - " print(\"Updated Inventory:\")\n", - "for product, quantity in inventory.items():\n", + " customer_orders[product] = quantity\n", + " for product in customer_orders:\n", + " icustomer_orders[product] -= 1\n", + " print(\"updated customer_orders:\")\n", + "for product, quantity in customer_orders.items():\n", " print(f\"{product}: {quantity}\")" ] }, From 7f93b86234bcdbbbf3ef71c90ef2a037bb30adf6 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 16:01:19 +0200 Subject: [PATCH 12/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 60 +++++++++++++++----------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index f9eb2bf8..7af9b5b3 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -77,46 +77,44 @@ " break\n", " except ValueError:\n", " print(\"Please enter a valid integer.\")\n", + "\n", "customer_orders = set()\n", - "for i in range(4):\n", - " product = input(f\"Enter product {i+1} (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", + "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + "while True:\n", + " product = input(\"Enter a product (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", + " \n", " if product in products_list:\n", " customer_orders.add(product)\n", + " print(f\"{product} has been added to the order.\")\n", " else:\n", " print(f\"{product} is not a valid choice and will not be added.\")\n", - " while:\n", - " product = input(f'Enter yes to add {product} to the order or no to skip: ').strip().lower() add_product = input(\"Enter yes to add the product to the order or no to skip: \").strip().lower()\n", - " if add_product == 'yes':\n", - " customer_orders.add(product)\n", - " print(f\"{product} has been added to the order.\")\n", - " break\n", - " elif add_product == 'no':\n", - " print(f\"{product} will not be added to the order.\")\n", - " break\n", - " else:\n", - "print(\"products in order:\", customer_orders)\n", + " add_more = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " \n", + " if add_more != 'yes':\n", + " break\n", "\n", - "total_ordered: int = len(customer_orders)\n", - "total_available: int = len(products_list)\n", - "percentage: float = (total_ordered / total_available) * 100\n", - "print(f\"total products ordered: {total_ordered}\")\n", - "print(f\"percentage of products ordered: {percentage}%\")\n", + "print(\"Products in Order:\", customer_orders)\n", "\n", - "order_status = ('total products ordered', 'percentage ordered')\n", + "total_ordered = len(customer_orders)\n", + "total_available = len(products_list)\n", + "percentage = (total_ordered / total_available) * 100\n", "\n", - "print(\"\\norder Statistics:\")\n", - "print(f\"Total products ordered: {order_status[0]}\")\n", - "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", + "order_status = (total_ordered, percentage)\n", "\n", - "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain'] \n", - "customer_orders = set() \n", - "for product in products_list:\n", - " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", - " customer_orders[product] = quantity\n", - " for product in customer_orders:\n", - " icustomer_orders[product] -= 1\n", - " print(\"updated customer_orders:\")\n", - "for product, quantity in customer_orders.items():\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"insufficient inventory for {product}, cannot fulfill order.\")\n", + "\n", + "# Step 6: Print the updated inventory\n", + "print(\"\\nupdated inventory:\")\n", + "for product, quantity in inventory.items():\n", " print(f\"{product}: {quantity}\")" ] }, From dfb0252ebcb0ad5295e159fea6617ec48ccaff61 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 16:31:03 +0200 Subject: [PATCH 13/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 7af9b5b3..8fb69479 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -94,7 +94,7 @@ " if add_more != 'yes':\n", " break\n", "\n", - "print(\"Products in Order:\", customer_orders)\n", + "print(\"products in order:\", customer_orders)\n", "\n", "total_ordered = len(customer_orders)\n", "total_available = len(products_list)\n", @@ -103,16 +103,19 @@ "order_status = (total_ordered, percentage)\n", "\n", "print(\"\\nOrder Statistics:\")\n", - "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "print(f\"total products ordered: {order_status[0]}\")\n", + "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", "\n", "for product in customer_orders:\n", - " if inventory[product] > 0:\n", + " if product in inventory and inventory[product] > 0:\n", " inventory[product] -= 1\n", + " print(f\"Successfully ordered {product}. Remaining: {inventory[product]}\")\n", + " elif product in inventory and inventory[product] == 0:\n", + " print(f\"Error: {product} is out of stock.\")\n", " else:\n", - " print(f\"insufficient inventory for {product}, cannot fulfill order.\")\n", + " print(f\"Error: {product} was not found in the inventory system.\")\n", + "\n", "\n", - "# Step 6: Print the updated inventory\n", "print(\"\\nupdated inventory:\")\n", "for product, quantity in inventory.items():\n", " print(f\"{product}: {quantity}\")" From fa7265648082acedcafac760969a1b6cdff3ab9d Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 16:35:24 +0200 Subject: [PATCH 14/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8fb69479..ddf6249c 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -110,11 +110,7 @@ " if product in inventory and inventory[product] > 0:\n", " inventory[product] -= 1\n", " print(f\"Successfully ordered {product}. Remaining: {inventory[product]}\")\n", - " elif product in inventory and inventory[product] == 0:\n", - " print(f\"Error: {product} is out of stock.\")\n", - " else:\n", - " print(f\"Error: {product} was not found in the inventory system.\")\n", - "\n", + " \n", "\n", "print(\"\\nupdated inventory:\")\n", "for product, quantity in inventory.items():\n", From 83c9f333616cf615645d44011720449d35f2609c Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 16:38:33 +0200 Subject: [PATCH 15/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index ddf6249c..e9e51729 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -79,7 +79,6 @@ " print(\"Please enter a valid integer.\")\n", "\n", "customer_orders = set()\n", - "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "\n", "while True:\n", " product = input(\"Enter a product (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", @@ -102,7 +101,7 @@ "\n", "order_status = (total_ordered, percentage)\n", "\n", - "print(\"\\nOrder Statistics:\")\n", + "print(\"\\norder statistics:\")\n", "print(f\"total products ordered: {order_status[0]}\")\n", "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", "\n", From 993dca5fb35e36a477f79d707addb6850aa4fcb6 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 17:27:38 +0200 Subject: [PATCH 16/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 47 +++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index e9e51729..a1443109 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -113,7 +113,52 @@ "\n", "print(\"\\nupdated inventory:\")\n", "for product, quantity in inventory.items():\n", - " print(f\"{product}: {quantity}\")" + " print(f\"{product}: {quantity}\")\n", + "\n", + "def initialize_inventory (products):\n", + " inventory = {}\n", + " for product in products:\n", + " inventory[product] = 0\n", + " return inventory\n", + "\n", + "def get_customer_orders(): \n", + " orders = []\n", + " while True:\n", + " order = input(\"Enter a product to order (or 'done' to finish): \")\n", + " if order.lower() == 'done':\n", + " break\n", + " orders.append(order)\n", + " return orders\n", + "\n", + "def update_inventory(inventory, customer_orders):\n", + " for order in orders:\n", + " if order in inventory:\n", + " inventory[order] += 1\n", + " return inventory\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " order_statistics = ('total products ordered', 'percentage of unique products ordered')\n", + " total_products_ordered = len(customer_orders)\n", + " unique_products_ordered = len(set(customer_orders))\n", + " percentage_unique = (unique_products_ordered / total_products_ordered * 100) if total_products_ordered > 0 else 0\n", + " return total_products_ordered, percentage_unique\n", + " order_statistics = ('total products ordered', 'percentage of unique products ordered')\n", + "def print_order_statistics():\n", + " total_products_ordered, percentage_unique = calculate_order_statistics(customer_orders, products)\n", + " print(f\"Total products ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of unique products ordered: {percentage_unique:.2f}%\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\") \n", + "\n", + "def execute_the_program():\n", + "\n", + "def manage_customer_orders():\n", + " \n", + "\n", + "\n" ] }, { From f91aab15c662f3cf414e264046cadc69f2b5ca38 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Tue, 14 Apr 2026 18:30:35 +0200 Subject: [PATCH 17/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 57 +++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index a1443109..f6ca0b75 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -115,16 +115,26 @@ "for product, quantity in inventory.items():\n", " print(f\"{product}: {quantity}\")\n", "\n", - "def initialize_inventory (products):\n", - " inventory = {}\n", + "def initialize_inventory(products: list[str]) -> dict[str, int]:\n", + " inventory: dict[str, int] = {}\n", + " \n", " for product in products:\n", - " inventory[product] = 0\n", + " # Loop until a valid integer is entered for each product\n", + " while True:\n", + " try:\n", + " quantity: int = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " break # Exit the while loop and move to the next product\n", + " except ValueError:\n", + " # This catches cases where input is not a whole number\n", + " print(\"Invalid input. Please enter a valid integer for the quantity.\")\n", + " \n", " return inventory\n", "\n", "def get_customer_orders(): \n", - " orders = []\n", + " orders = ()\n", " while True:\n", - " order = input(\"Enter a product to order (or 'done' to finish): \")\n", + " order = input(\"Enter a product to order (or 'done' to finish): \") .strip().lower()\n", " if order.lower() == 'done':\n", " break\n", " orders.append(order)\n", @@ -136,17 +146,18 @@ " inventory[order] += 1\n", " return inventory\n", "\n", - "def calculate_order_statistics(customer_orders, products):\n", - " order_statistics = ('total products ordered', 'percentage of unique products ordered')\n", - " total_products_ordered = len(customer_orders)\n", - " unique_products_ordered = len(set(customer_orders))\n", - " percentage_unique = (unique_products_ordered / total_products_ordered * 100) if total_products_ordered > 0 else 0\n", - " return total_products_ordered, percentage_unique\n", - " order_statistics = ('total products ordered', 'percentage of unique products ordered')\n", - "def print_order_statistics():\n", - " total_products_ordered, percentage_unique = calculate_order_statistics(customer_orders, products)\n", - " print(f\"Total products ordered: {total_products_ordered}\")\n", - " print(f\"Percentage of unique products ordered: {percentage_unique:.2f}%\")\n", + "def calculate_order_statistics(customer_orders, products)\n", + " total_ordered = len(customer_orders)\n", + " total_available = len(products)\n", + " percentage = (total_ordered / total_available) * 100\n", + " return total_ordered, percentage\n", + "\n", + "\n", + "def print_order_statistics(total_ordered, percentage):\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total products ordered: {total_ordered}\")\n", + " print(f\"Percentage of products ordered: {percentage:.2f}%\") \n", + "\n", "\n", "def print_updated_inventory(inventory):\n", " print(\"Updated Inventory:\")\n", @@ -154,8 +165,22 @@ " print(f\"{product}: {quantity}\") \n", "\n", "def execute_the_program():\n", + " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + " inventory = initialize_inventory(products_list)\n", + " customer_orders = get_customer_orders()\n", + " updated_inventory = update_inventory(inventory, customer_orders)\n", + " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", + " print_order_statistics(total_ordered, percentage)\n", + " print_updated_inventory(updated_inventory)\n", "\n", "def manage_customer_orders():\n", + " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + " inventory = initialize_inventory(products_list)\n", + " customer_orders = get_customer_orders()\n", + " updated_inventory = update_inventory(inventory, customer_orders)\n", + " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", + " print_order_statistics(total_ordered, percentage)\n", + " print_updated_inventory(updated_inventory)\n", " \n", "\n", "\n" From 6bc88b78ce9c8cbcdc78c8f5e2118249b92896ed Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 12:19:46 +0200 Subject: [PATCH 18/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 136 ++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 30 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index f6ca0b75..ca78085e 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -115,6 +115,29 @@ "for product, quantity in inventory.items():\n", " print(f\"{product}: {quantity}\")\n", "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "def initialize_inventory(products: list[str]) -> dict[str, int]:\n", " inventory: dict[str, int] = {}\n", " \n", @@ -129,51 +152,108 @@ " # This catches cases where input is not a whole number\n", " print(\"Invalid input. Please enter a valid integer for the quantity.\")\n", " \n", - " return inventory\n", - "\n", + " return inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ "def get_customer_orders(): \n", - " orders = ()\n", + " orders = input(\"Enter the products you want to order, separated by commas: \").strip().lower()\n", " while True:\n", - " order = input(\"Enter a product to order (or 'done' to finish): \") .strip().lower()\n", + " order = input(\"Enter a product to order (or 'done' to finish): \")\n", " if order.lower() == 'done':\n", " break\n", " orders.append(order)\n", - " return orders\n", - "\n", + " return orders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ "def update_inventory(inventory, customer_orders):\n", - " for order in orders:\n", - " if order in inventory:\n", - " inventory[order] += 1\n", - " return inventory\n", - "\n", - "def calculate_order_statistics(customer_orders, products)\n", + " for product in inventory:\n", + " if product in customer_orders:\n", + " inventory[product] -= 1\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", " total_ordered = len(customer_orders)\n", " total_available = len(products)\n", " percentage = (total_ordered / total_available) * 100\n", - " return total_ordered, percentage\n", - "\n", - "\n", - "def print_order_statistics(total_ordered, percentage):\n", + " return total_ordered, percentage\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", " print(\"\\nOrder Statistics:\")\n", - " print(f\"Total products ordered: {total_ordered}\")\n", - " print(f\"Percentage of products ordered: {percentage:.2f}%\") \n", - "\n", - "\n", + " print(f\"Total products ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of products ordered: {order_statistics[1]:.2f}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ "def print_updated_inventory(inventory):\n", - " print(\"Updated Inventory:\")\n", + " print(\"updated inventory:\")\n", " for product, quantity in inventory.items():\n", - " print(f\"{product}: {quantity}\") \n", - "\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ "def execute_the_program():\n", + " \n", " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", " inventory = initialize_inventory(products_list)\n", " customer_orders = get_customer_orders()\n", " updated_inventory = update_inventory(inventory, customer_orders)\n", " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", " print_order_statistics(total_ordered, percentage)\n", - " print_updated_inventory(updated_inventory)\n", + " print_updated_inventory(updated_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ "\n", "def manage_customer_orders():\n", + "\n", " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", " inventory = initialize_inventory(products_list)\n", " customer_orders = get_customer_orders()\n", @@ -181,9 +261,7 @@ " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", " print_order_statistics(total_ordered, percentage)\n", " print_updated_inventory(updated_inventory)\n", - " \n", - "\n", - "\n" + " \n" ] }, { @@ -191,9 +269,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "\n" - ] + "source": [] } ], "metadata": { From 92716de45780f155d0cc4c0f3804c80911394da0 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 14:05:31 +0200 Subject: [PATCH 19/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 67 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index ca78085e..0d64c13b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -138,36 +138,36 @@ "metadata": {}, "outputs": [], "source": [ - "def initialize_inventory(products: list[str]) -> dict[str, int]:\n", - " inventory: dict[str, int] = {}\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", " \n", " for product in products:\n", - " # Loop until a valid integer is entered for each product\n", + " \n", " while True:\n", " try:\n", - " quantity: int = int(input(f\"Enter the quantity for {product}: \"))\n", + " quantity: int = int(input(f\"enter the quantity for {product}: \"))\n", " inventory[product] = quantity\n", - " break # Exit the while loop and move to the next product\n", + " break \n", " except ValueError:\n", - " # This catches cases where input is not a whole number\n", - " print(\"Invalid input. Please enter a valid integer for the quantity.\")\n", + " \n", + " print(\"invalid input. Please enter a valid integer for the quantity.\")\n", " \n", " return inventory\n" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def get_customer_orders(): \n", - " orders = input(\"Enter the products you want to order, separated by commas: \").strip().lower()\n", + " orders = ()\n", " while True:\n", - " order = input(\"Enter a product to order (or 'done' to finish): \")\n", - " if order.lower() == 'done':\n", + " order = input(\"enter a product to order (or 'done' to finish): \").strip().lower()\n", + " if order == 'done':\n", " break\n", - " orders.append(order)\n", + " orders += (order,)\n", " return orders" ] }, @@ -180,40 +180,42 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ - "def update_inventory(inventory, customer_orders):\n", + "def update_inventory(customer_orders, inventory):\n", " for product in inventory:\n", - " if product in customer_orders:\n", + " if product in customer_orders: # general idea: scroll through customer orders and update inventory only if the product exists\n", " inventory[product] -= 1\n", " return inventory" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "def calculate_order_statistics(customer_orders, products):\n", " total_ordered = len(customer_orders)\n", " total_available = len(products)\n", - " percentage = (total_ordered / total_available) * 100\n", - " return total_ordered, percentage\n" + " order_statistics = (total_ordered / total_available) * 100\n", + " return order_statistics\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def print_order_statistics(order_statistics):\n", - " print(\"\\nOrder Statistics:\")\n", - " print(f\"Total products ordered: {order_statistics[0]}\")\n", - " print(f\"Percentage of products ordered: {order_statistics[1]:.2f}%\")\n" + " print(\"\\norder Statistics:\")\n", + " print(f\"total products ordered: {order_statistics[0]}\")\n", + " print(f\"percentage of unique products ordered: {order_statistics[1]:.2f}%\")\n" ] }, { @@ -230,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -239,15 +241,16 @@ " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", " inventory = initialize_inventory(products_list)\n", " customer_orders = get_customer_orders()\n", - " updated_inventory = update_inventory(inventory, customer_orders)\n", - " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", - " print_order_statistics(total_ordered, percentage)\n", - " print_updated_inventory(updated_inventory)" + " updated_inventory = update_inventory(customer_orders, inventory)\n", + " order_statistics= calculate_order_statistics(customer_orders, products_list)\n", + " print_order_statistics(order_statistics)\n", + " print_updated_inventory(updated_inventory)\n", + " return\n" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -257,10 +260,12 @@ " products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", " inventory = initialize_inventory(products_list)\n", " customer_orders = get_customer_orders()\n", - " updated_inventory = update_inventory(inventory, customer_orders)\n", - " total_ordered, percentage = calculate_order_statistics(customer_orders, products_list)\n", - " print_order_statistics(total_ordered, percentage)\n", + " updated_inventory = update_inventory(customer_orders, inventory)\n", + " order_statistics= calculate_order_statistics(customer_orders, products_list)\n", + " print_order_statistics(order_statistics)\n", " print_updated_inventory(updated_inventory)\n", + " return\n", + "\n", " \n" ] }, From 0fb6a22dffc4e3ccb722b26e20365d5302c4b6b8 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 15:15:13 +0200 Subject: [PATCH 20/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 48 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 0d64c13b..0c6aa14f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -145,9 +145,9 @@ " \n", " while True:\n", " try:\n", - " quantity: int = int(input(f\"enter the quantity for {product}: \"))\n", - " inventory[product] = quantity\n", - " break \n", + " \n", + " inventory[product] = quantity\n", + " break \n", " except ValueError:\n", " \n", " print(\"invalid input. Please enter a valid integer for the quantity.\")\n", @@ -157,12 +157,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "def get_customer_orders(): \n", - " orders = ()\n", + " # general idea: use a colection that does not allow duplicates \n", + "# and only valid products to be added.\n", + " orders = set()\n", " while True:\n", " order = input(\"enter a product to order (or 'done' to finish): \").strip().lower()\n", " if order == 'done':\n", @@ -180,29 +182,45 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", - " for product in inventory:\n", - " if product in customer_orders: # general idea: scroll through customer orders and update inventory only if the product exists\n", + " for product in customer_orders:\n", + " if product in inventory: # general idea: scroll through customer orders and update inventory only if the product exists\n", " inventory[product] -= 1\n", " return inventory" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "def calculate_order_statistics(customer_orders, products):\n", - " total_ordered = len(customer_orders)\n", - " total_available = len(products)\n", - " order_statistics = (total_ordered / total_available) * 100\n", + " \"\"\"\n", + " Calculates order statistics: total products ordered and the percentage \n", + " of unique products relative to the total number of items ordered.\n", + " \"\"\"\n", + " total_products_ordered = len(customer_orders)\n", + " \n", + " # Handle empty orders to avoid division by zero errors\n", + " if total_products_ordered == 0:\n", + " return 0, 0.0\n", + "\n", + " # Identify unique items by converting the order list to a set\n", + " # Using a set automatically removes all duplicate entries\n", + " unique_products_ordered = len(set(customer_orders))\n", + " \n", + " # Calculate percentage based on unique items ordered vs total items ordered\n", + " percentage_unique = (unique_products_ordered / total_products_ordered) * 100\n", + " \n", + " # Package the results into a tuple for the final return\n", + " order_statistics = (total_products_ordered, percentage_unique)\n", + " \n", " return order_statistics\n", - "\n", "\n" ] }, @@ -245,7 +263,8 @@ " order_statistics= calculate_order_statistics(customer_orders, products_list)\n", " print_order_statistics(order_statistics)\n", " print_updated_inventory(updated_inventory)\n", - " return\n" + " return\n", + "\n" ] }, { @@ -266,6 +285,7 @@ " print_updated_inventory(updated_inventory)\n", " return\n", "\n", + "\n", " \n" ] }, From 4495c721780bbde88cf444ef4a78017c02c9090d Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 16:24:10 +0200 Subject: [PATCH 21/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 0c6aa14f..2f70746b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -142,22 +142,22 @@ " inventory = {}\n", " \n", " for product in products:\n", - " \n", - " while True:\n", - " try:\n", - " \n", - " inventory[product] = quantity\n", - " break \n", - " except ValueError:\n", - " \n", - " print(\"invalid input. Please enter a valid integer for the quantity.\")\n", + "\n", + " while True:\n", + " quantity_input = input(f\"Enter the quantity for {product}: \") or '0'\n", + " try:\n", + " quantity = int(quantity_input)\n", + " inventory[product] = quantity\n", + " break\n", + " except ValueError:\n", + " print(\"Please enter a valid integer.\") \n", " \n", " return inventory\n" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -167,9 +167,9 @@ " orders = set()\n", " while True:\n", " order = input(\"enter a product to order (or 'done' to finish): \").strip().lower()\n", - " if order == 'done':\n", + " if order == 'done': #only valid products should be added to the order.\n", " break\n", - " orders += (order,)\n", + " orders.add(order)\n", " return orders" ] }, @@ -182,20 +182,20 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", " for product in customer_orders:\n", " if product in inventory: # general idea: scroll through customer orders and update inventory only if the product exists\n", - " inventory[product] -= 1\n", + " inventory[product] -= 1 # before updating, check if the product exists in the inventory to avoid errors. \n", " return inventory" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -215,7 +215,7 @@ " unique_products_ordered = len(set(customer_orders))\n", " \n", " # Calculate percentage based on unique items ordered vs total items ordered\n", - " percentage_unique = (unique_products_ordered / total_products_ordered) * 100\n", + " percentage_unique = (unique_products_ordered / products) * 100\n", " \n", " # Package the results into a tuple for the final return\n", " order_statistics = (total_products_ordered, percentage_unique)\n", @@ -226,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ From 0bb4e0db90f3b7e6bd2e28aaa95467a7851c7e84 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 17:04:50 +0200 Subject: [PATCH 22/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 2f70746b..c1057c0f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -157,19 +157,27 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ - "def get_customer_orders(): \n", - " # general idea: use a colection that does not allow duplicates \n", - "# and only valid products to be added.\n", + "def get_customer_orders():\n", + " \n", " orders = set()\n", + " \n", " while True:\n", - " order = input(\"enter a product to order (or 'done' to finish): \").strip().lower()\n", - " if order == 'done': #only valid products should be added to the order.\n", + " \n", + " order = input(\"Enter onlya valid product: \").strip().lower()\n", + " \n", + " if not order:\n", " break\n", - " orders.add(order)\n", + " \n", + " if order in inventory:\n", + " orders.add(order)\n", + " print(f\"Added: {order}\")\n", + " else:\n", + " print(f\"Error: '{order}' is not a valid product.\")\n", + " \n", " return orders" ] }, @@ -182,20 +190,24 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", " for product in customer_orders:\n", - " if product in inventory: # general idea: scroll through customer orders and update inventory only if the product exists\n", - " inventory[product] -= 1 # before updating, check if the product exists in the inventory to avoid errors. \n", - " return inventory" + " if product in inventory: \n", + " inventory[product] -= 1\n", + " if product not in inventory:\n", + " print(f\"Error: '{product}' is not available.\")\n", + " return inventory\n", + "\n", + " " ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -204,20 +216,16 @@ " Calculates order statistics: total products ordered and the percentage \n", " of unique products relative to the total number of items ordered.\n", " \"\"\"\n", - " total_products_ordered = len(customer_orders)\n", + " total_products_ordered = len(products)\n", " \n", - " # Handle empty orders to avoid division by zero errors\n", " if total_products_ordered == 0:\n", " return 0, 0.0\n", "\n", - " # Identify unique items by converting the order list to a set\n", - " # Using a set automatically removes all duplicate entries\n", - " unique_products_ordered = len(set(customer_orders))\n", + " unique_products_ordered = len(customer_orders)\n", " \n", - " # Calculate percentage based on unique items ordered vs total items ordered\n", - " percentage_unique = (unique_products_ordered / products) * 100\n", + " percentage_unique = (unique_products_ordered / total_products_ordered) * 100\n", " \n", - " # Package the results into a tuple for the final return\n", + "\n", " order_statistics = (total_products_ordered, percentage_unique)\n", " \n", " return order_statistics\n", From 6e237cccae9f067cedbb682a4b218274fee7e546 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 17:35:42 +0200 Subject: [PATCH 23/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 44 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index c1057c0f..2d44f16f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -144,7 +144,7 @@ " for product in products:\n", "\n", " while True:\n", - " quantity_input = input(f\"Enter the quantity for {product}: \") or '0'\n", + " quantity_input = input(f\"Enter the quantity for {product}: \") \n", " try:\n", " quantity = int(quantity_input)\n", " inventory[product] = quantity\n", @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ @@ -167,17 +167,13 @@ " \n", " while True:\n", " \n", - " order = input(\"Enter onlya valid product: \").strip().lower()\n", + " order = input(\"Enter only a valid product: \").strip().lower()\n", " \n", - " if not order:\n", - " break\n", - " \n", - " if order in inventory:\n", - " orders.add(order)\n", - " print(f\"Added: {order}\")\n", - " else:\n", - " print(f\"Error: '{order}' is not a valid product.\")\n", - " \n", + " if not order: \n", + " choice = input('do you want to add another product? (yes/no): ').strip().lower()\n", + " if choice == 'no':\n", + " break\n", + " orders.add(order)\n", " return orders" ] }, @@ -190,16 +186,16 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", " for product in customer_orders:\n", - " if product in inventory: \n", + " if product in inventory: \n", " inventory[product] -= 1\n", - " if product not in inventory:\n", - " print(f\"Error: '{product}' is not available.\")\n", + " if product not in inventory:\n", + " print(f\"Error: '{product}' is not available.\")\n", " return inventory\n", "\n", " " @@ -207,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ @@ -216,17 +212,17 @@ " Calculates order statistics: total products ordered and the percentage \n", " of unique products relative to the total number of items ordered.\n", " \"\"\"\n", - " total_products_ordered = len(products)\n", + " total_products_ordered = len(customer_orders)\n", " \n", " if total_products_ordered == 0:\n", " return 0, 0.0\n", "\n", - " unique_products_ordered = len(customer_orders)\n", + " unique_products_ordered = len(products)\n", " \n", - " percentage_unique = (unique_products_ordered / total_products_ordered) * 100\n", + " percentage_unique_products_ordered = (unique_products_ordered / total_products_ordered) * 100\n", " \n", "\n", - " order_statistics = (total_products_ordered, percentage_unique)\n", + " order_statistics = (total_products_ordered, percentage_unique_products_ordered)\n", " \n", " return order_statistics\n", "\n" @@ -234,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ @@ -258,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ @@ -277,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ From 4e24d4479d0ddedd59d3e9016730061f35d7fb40 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 17:53:12 +0200 Subject: [PATCH 24/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 2d44f16f..2e2d7d65 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -167,13 +167,13 @@ " \n", " while True:\n", " \n", - " order = input(\"Enter only a valid product: \").strip().lower()\n", + " order = input(\"Enter only a valid product and validate it: \").strip().lower()\n", " \n", " if not order: \n", " choice = input('do you want to add another product? (yes/no): ').strip().lower()\n", " if choice == 'no':\n", " break\n", - " orders.add(order)\n", + " \n", " return orders" ] }, @@ -186,13 +186,13 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", " for product in customer_orders:\n", - " if product in inventory: \n", + " if product in inventory and inventory[product] > 0: \n", " inventory[product] -= 1\n", " if product not in inventory:\n", " print(f\"Error: '{product}' is not available.\")\n", @@ -203,21 +203,18 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def calculate_order_statistics(customer_orders, products):\n", - " \"\"\"\n", - " Calculates order statistics: total products ordered and the percentage \n", - " of unique products relative to the total number of items ordered.\n", - " \"\"\"\n", + " \n", " total_products_ordered = len(customer_orders)\n", " \n", " if total_products_ordered == 0:\n", " return 0, 0.0\n", "\n", - " unique_products_ordered = len(products)\n", + " unique_products_ordered = len(set(customer_orders))\n", " \n", " percentage_unique_products_ordered = (unique_products_ordered / total_products_ordered) * 100\n", " \n", @@ -225,6 +222,7 @@ " order_statistics = (total_products_ordered, percentage_unique_products_ordered)\n", " \n", " return order_statistics\n", + "\n", "\n" ] }, From 5e62dda5c9f2b5b00b2d4a38cd7f24b724f18388 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 18:42:16 +0200 Subject: [PATCH 25/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 2e2d7d65..7a72a6ef 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -205,7 +205,16 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "IndentationError", + "evalue": "unexpected indent (970161005.py, line 13)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[70]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mreturn order_statistics\u001b[39m\n ^\n\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m unexpected indent\n" + ] + } + ], "source": [ "def calculate_order_statistics(customer_orders, products):\n", " \n", @@ -216,7 +225,7 @@ "\n", " unique_products_ordered = len(set(customer_orders))\n", " \n", - " percentage_unique_products_ordered = (unique_products_ordered / total_products_ordered) * 100\n", + " percentage_unique_products_ordered = (unique_products_ordered / products) * 100\n", " \n", "\n", " order_statistics = (total_products_ordered, percentage_unique_products_ordered)\n", From 1bfd6d1f3e2370758661f90938089f89e093ea0f Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 20:02:54 +0200 Subject: [PATCH 26/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 55 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 7a72a6ef..89593f80 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -157,24 +157,32 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "def get_customer_orders():\n", - " \n", + " products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", " orders = set()\n", " \n", - " while True:\n", " \n", - " order = input(\"Enter only a valid product and validate it: \").strip().lower()\n", + " while True:\n", + " order = input(\"Enter a valid product name to add to your order: \").strip().lower()\n", + " \n", + " if order in products:\n", + " customer_orders.add(order)\n", + " print(f\"'{order}' has been added to your order.\")\n", + " else:\n", + " print(f\"Error: '{order}' is not a valid product.\")\n", " \n", - " if not order: \n", - " choice = input('do you want to add another product? (yes/no): ').strip().lower()\n", - " if choice == 'no':\n", - " break\n", + " # Prompt to continue or stop\n", + " choice = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if choice == 'no':\n", + " break\n", " \n", - " return orders" + " return orders\n", + "\n", + " " ] }, { @@ -186,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ @@ -194,7 +202,7 @@ " for product in customer_orders:\n", " if product in inventory and inventory[product] > 0: \n", " inventory[product] -= 1\n", - " if product not in inventory:\n", + " else:\n", " print(f\"Error: '{product}' is not available.\")\n", " return inventory\n", "\n", @@ -203,33 +211,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [ - { - "ename": "IndentationError", - "evalue": "unexpected indent (970161005.py, line 13)", - "output_type": "error", - "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[70]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mreturn order_statistics\u001b[39m\n ^\n\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m unexpected indent\n" - ] - } - ], + "outputs": [], "source": [ "def calculate_order_statistics(customer_orders, products):\n", - " \n", " total_products_ordered = len(customer_orders)\n", - " \n", + "\n", " if total_products_ordered == 0:\n", " return 0, 0.0\n", "\n", - " unique_products_ordered = len(set(customer_orders))\n", - " \n", - " percentage_unique_products_ordered = (unique_products_ordered / products) * 100\n", - " \n", + " percentage_unique_products_ordered = (total_products_ordered / len(products)) * 100\n", "\n", " order_statistics = (total_products_ordered, percentage_unique_products_ordered)\n", - " \n", + "\n", " return order_statistics\n", "\n", "\n" @@ -261,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ From 868efc657e821bfcc1708e8c8e8ef476a2c93418 Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Wed, 15 Apr 2026 20:36:16 +0200 Subject: [PATCH 27/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 89593f80..4c0e01c4 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -157,32 +157,35 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# Define the product list as a global variable\n", + "PRODUCTS_LIST = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", "def get_customer_orders():\n", - " products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - " orders = set()\n", - " \n", + " orders = set() # Local variable to collect customer orders\n", " \n", " while True:\n", + " # Prompt the user for input\n", " order = input(\"Enter a valid product name to add to your order: \").strip().lower()\n", " \n", - " if order in products:\n", - " customer_orders.add(order)\n", + " if order in PRODUCTS_LIST:\n", + " orders.add(order) # Update local `orders` set\n", " print(f\"'{order}' has been added to your order.\")\n", " else:\n", - " print(f\"Error: '{order}' is not a valid product.\")\n", + " print(f\"Error: '{order}' is not a valid product, or product is not available.\")\n", " \n", - " # Prompt to continue or stop\n", + " # Prompt the user to continue or stop adding products\n", " choice = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", " if choice == 'no':\n", " break\n", - " \n", - " return orders\n", + " \n", + " return orders # Return the local `orders` set\n", "\n", - " " + "\n", + " " ] }, { @@ -194,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 80, "metadata": {}, "outputs": [], "source": [ @@ -203,7 +206,7 @@ " if product in inventory and inventory[product] > 0: \n", " inventory[product] -= 1\n", " else:\n", - " print(f\"Error: '{product}' is not available.\")\n", + " print(f\"Error: '{product}' is not available, or don't exist in inventory.\")\n", " return inventory\n", "\n", " " @@ -211,17 +214,18 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ "def calculate_order_statistics(customer_orders, products):\n", " total_products_ordered = len(customer_orders)\n", + " total_available_products = len(products)\n", "\n", " if total_products_ordered == 0:\n", " return 0, 0.0\n", "\n", - " percentage_unique_products_ordered = (total_products_ordered / len(products)) * 100\n", + " percentage_unique_products_ordered = (total_products_ordered / total_available_products) * 100\n", "\n", " order_statistics = (total_products_ordered, percentage_unique_products_ordered)\n", "\n", @@ -232,12 +236,12 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def print_order_statistics(order_statistics):\n", - " print(\"\\norder Statistics:\")\n", + " print(\"\\norder statistics:\")\n", " print(f\"total products ordered: {order_statistics[0]}\")\n", " print(f\"percentage of unique products ordered: {order_statistics[1]:.2f}%\")\n" ] From 20afbe1f7e86769fab899134698d02aaaf20c60f Mon Sep 17 00:00:00 2001 From: nailaikhenazenni-afk Date: Thu, 16 Apr 2026 09:32:43 +0200 Subject: [PATCH 28/28] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 52 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 4c0e01c4..b8b68c1e 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -157,32 +157,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, "outputs": [], "source": [ - "# Define the product list as a global variable\n", - "PRODUCTS_LIST = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - "\n", "def get_customer_orders():\n", " orders = set() # Local variable to collect customer orders\n", - " \n", + " valid_products = {'t-shirt', 'mug', 'hat', 'book', 'keychain'}\n", + "\n", " while True:\n", " # Prompt the user for input\n", " order = input(\"Enter a valid product name to add to your order: \").strip().lower()\n", " \n", - " if order in PRODUCTS_LIST:\n", - " orders.add(order) # Update local `orders` set\n", + " if order in valid_products:\n", + " orders.add(order) # Add order to set\n", " print(f\"'{order}' has been added to your order.\")\n", " else:\n", - " print(f\"Error: '{order}' is not a valid product, or product is not available.\")\n", - " \n", - " # Prompt the user to continue or stop adding products\n", - " choice = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " print(f\"Error: '{order}' is not a valid product.\")\n", + "\n", + " # After every attempt, ask if they want to continue adding\n", + " choice = \"\"\n", + " while choice not in {\"yes\", \"no\"}:\n", + " choice = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if choice not in {\"yes\", \"no\"}:\n", + " print(\"Please enter 'yes' or 'no'.\")\n", + "\n", " if choice == 'no':\n", " break\n", - " \n", - " return orders # Return the local `orders` set\n", + " return orders\n", "\n", "\n", " " @@ -197,19 +199,23 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 85, "metadata": {}, "outputs": [], "source": [ "def update_inventory(customer_orders, inventory):\n", + " \"\"\"\n", + " Iterates through customer orders and reduces inventory counts for valid items.\n", + " \"\"\"\n", " for product in customer_orders:\n", - " if product in inventory and inventory[product] > 0: \n", + " # Check if product is a key in the inventory and has stock available\n", + " if product in inventory and inventory[product] > 0:\n", " inventory[product] -= 1\n", - " else:\n", - " print(f\"Error: '{product}' is not available, or don't exist in inventory.\")\n", - " return inventory\n", - "\n", - " " + " else:\n", + " # Handle cases where the item is out of stock or misspelled\n", + " print(f\"Error: '{product}' is not available or doesn't exist in inventory.\")\n", + " \n", + " return inventory\n" ] }, { @@ -248,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -260,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 86, "metadata": {}, "outputs": [], "source": [ @@ -279,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 87, "metadata": {}, "outputs": [], "source": [