From 9ab56be04739e3820a7c08e38d2ad83f28fe9999 Mon Sep 17 00:00:00 2001 From: nadiyashahaibi-DA Date: Tue, 21 Jul 2026 19:34:49 +0100 Subject: [PATCH] Completed lab exercises --- lab-python-data-structures.ipynb | 192 ++++++++++++++++++++++++++++++- 1 file changed, 191 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..a2fe564c 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,196 @@ "\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": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products) " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity for t-shirt: 2\n", + "Enter quantity for mug: 1\n", + "Enter quantity for hat: 1\n", + "Enter quantity for book: 2\n", + "Enter quantity for keychain: 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 2, 'mug': 1, 'hat': 1, 'book': 2, 'keychain': 3}\n" + ] + } + ], + "source": [ + "inventory[\"t-shirt\"] = int(input(\"Enter quantity for t-shirt: \"))\n", + "inventory[\"mug\"] = int(input(\"Enter quantity for mug: \"))\n", + "inventory[\"hat\"] = int(input(\"Enter quantity for hat: \"))\n", + "inventory[\"book\"] = int(input(\"Enter quantity for book: \"))\n", + "inventory[\"keychain\"] = int(input(\"Enter quantity for keychain: \"))\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product 1: hat\n", + "Enter product 2: mug\n", + "Enter product 3: keychain\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer orders: {'mug', 'hat', 'keychain'}\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "\n", + "order1 = input(\"Enter product 1: \")\n", + "customer_orders.add(order1)\n", + "\n", + "\n", + "order2 = input(\"Enter product 2: \")\n", + "customer_orders.add(order2)\n", + "\n", + "\n", + "order3 = input(\"Enter product 3: \")\n", + "customer_orders.add(order3)\n", + "\n", + "print(\"Customer orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: \n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"Order Statistics: \")\n", + "print(\"Total Products Ordered: \", order_status[0])\n", + "print(\"Percentage of Products Ordered: \", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[order1] = inventory[order1] - 1\n", + "inventory[order2] = inventory[order2] - 1\n", + "inventory[order3] = inventory[order3] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory: \n", + "t-shirt: 2\n", + "mug: 0\n", + "hat: 0\n", + "book: 2\n", + "keychain: 2\n", + "keychain: 2\n" + ] + } + ], + "source": [ + "print(\"Updated Inventory: \")\n", + "print(\"t-shirt:\",inventory[\"t-shirt\"])\n", + "print(\"mug:\", inventory[\"mug\"])\n", + "print(\"hat:\", inventory[\"hat\"])\n", + "print(\"book:\", inventory[\"book\"])\n", + "print(\"keychain:\", inventory[\"keychain\"]) \n", + "print(\"keychain:\", inventory[\"keychain\"])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,