From 339c900b3d01d6a4f567dfb0751299e943f46da9 Mon Sep 17 00:00:00 2001 From: rmoind Date: Tue, 7 Oct 2025 14:54:59 +0200 Subject: [PATCH 1/2] lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..ba863005 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,19 @@ "\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": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "#template" + ] } ], "metadata": { From 690af56909c791bea80ff3e1c6eb14f6cb61175c Mon Sep 17 00:00:00 2001 From: rmoind Date: Tue, 7 Oct 2025 16:05:06 +0200 Subject: [PATCH 2/2] lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 333 ++++++++++++++++++++++++++++++- 1 file changed, 326 insertions(+), 7 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index ba863005..ae78b5fe 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -54,20 +54,339 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "vscode": { - "languageId": "plaintext" + "metadata": {}, + "outputs": [], + "source": [ + "#1. \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" } - }, + ], + "source": [ + "type(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, "outputs": [], "source": [ - "#template" + "#2.\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 7, 'mug': 6, 'hat': 5, 'book': 4, 'keychain': 3}\n" + ] + } + ], + "source": [ + "#3.\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('t-shirt', 7), ('mug', 6), ('hat', 5), ('book', 4), ('keychain', 3)])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "inventory.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# 4. \n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "set" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# 5.\n", + "for i in range(3):\n", + " order = input(\"Enter the name of a product to order (t-shirt, mug, hat, book, keychain): \")\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(f\"{order} is not available in the product list.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "# 6.\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 7.\n", + "total_products_ordered = len(customer_orders)\n", + "len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "percentage_of_products_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_ordered, percentage_of_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0% \n" + ] + } + ], + "source": [ + "# 8.\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_of_products_ordered}% \")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 6, 'mug': 5, 'hat': 4, 'book': 3, 'keychain': 2}\n" + ] + } + ], + "source": [ + "# 9.\n", + "for product in products:\n", + " inventory[product] -= 1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 6\n", + "mug: 5\n", + "hat: 4\n", + "book: 3\n", + "keychain: 2\n" + ] + } + ], + "source": [ + "# 10.\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -81,7 +400,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,