From e60cdcd1df4d712b005671d0e09061375f8be38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Beltr=C3=A1n?= Date: Mon, 12 Jan 2026 17:13:00 +0100 Subject: [PATCH 1/2] add first lab --- lab-python-data-structures.ipynb | 177 ++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..2b3ce37f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,184 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 2, 'mug': 2, 'book': 2, 'keychain': 2}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "inv_t_shirt = int(input(\"Add quantity of T-shirts in inventory: \"))\n", + "inventory[\"t-shirt\"]=inv_t_shirt\n", + "inv_mug = int(input(\"Add quantity of mugs in inventory: \"))\n", + "inventory[\"mug\"]=inv_mug\n", + "inv_book = int(input(\"Add quantity of books in inventory: \"))\n", + "inventory[\"book\"]=inv_book\n", + "inv_keychain = int(input(\"Add quantity of keychains in inventory: \"))\n", + "inventory[\"keychain\"]=inv_keychain\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 't-shirt', 'book'}\n" + ] + } + ], + "source": [ + "customer_order = set()\n", + "first_order = input(\"Please, add the first order from inventory products: \")\n", + "customer_order.add(first_order)\n", + "second_order = input(\"Please, add the second order from inventory products: \")\n", + "customer_order.add(second_order)\n", + "third_order = input(\"Please, add the third order from inventory products: \")\n", + "customer_order.add(third_order)\n", + "print(customer_order)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Total_products_ord = len(customer_order)\n", + "\n", + "Total_products_ord" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "75.0\n" + ] + } + ], + "source": [ + "Percentage = len(customer_order) / len(inventory) * 100\n", + "print(Percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('3', '75.0')\n" + ] + } + ], + "source": [ + "order_status = ()\n", + "order_status = order_status + (\"3\", \"75.0\")\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 75.0\n" + ] + } + ], + "source": [ + "print(f\"Order statistics:\\nTotal Products Ordered: {Total_products_ord}\\nPercentage of Products Ordered: {Percentage}\")\n", + "#en un principio había hecho 3 líneas de print, pero me apetecía saber de que manera podía saltar de línea el texto escrito." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 1, 'book': 1, 'keychain': 2}\n" + ] + } + ], + "source": [ + "inventory[\"book\"] -= 1\n", + "inventory[\"t-shirt\"]-= 1\n", + "inventory[\"mug\"]-= 1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 1\n", + "mug: 1\n", + "book: 1\n", + "keychain: 2\n" + ] + } + ], + "source": [ + "print(\"t-shirt: \", inventory[\"book\"])\n", + "print(\"mug: \", inventory[\"mug\"])\n", + "print(\"book: \", inventory[\"book\"])\n", + "print(\"keychain: \", inventory[\"keychain\"])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +241,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From 3b4dbcf84d70ff3c9ccf4f00d15f1a6bcdeb3d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Beltr=C3=A1n?= Date: Mon, 12 Jan 2026 17:22:44 +0100 Subject: [PATCH 2/2] add second try --- lab-python-data-structures.ipynb | 40 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 2b3ce37f..664ee406 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,19 +53,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': 2, 'mug': 2, 'book': 2, 'keychain': 2}\n" + "{'t-shirt': 2, 'mug': 2, 'book': 2, 'hat': 2, 'keychain': 2}\n" ] } ], "source": [ - "products = [\"t-shirt\", \"mug\", \"book\", \"keychain\"]\n", + "products = [\"t-shirt\", \"mug\", \"book\", \"hat\", \"keychain\"]\n", "inventory = {}\n", "inv_t_shirt = int(input(\"Add quantity of T-shirts in inventory: \"))\n", "inventory[\"t-shirt\"]=inv_t_shirt\n", @@ -73,6 +73,8 @@ "inventory[\"mug\"]=inv_mug\n", "inv_book = int(input(\"Add quantity of books in inventory: \"))\n", "inventory[\"book\"]=inv_book\n", + "inv_hat = int(input(\"Add quantity of hats in inventory: \"))\n", + "inventory[\"hat\"]=inv_hat\n", "inv_keychain = int(input(\"Add quantity of keychains in inventory: \"))\n", "inventory[\"keychain\"]=inv_keychain\n", "print(inventory)" @@ -80,14 +82,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'mug', 't-shirt', 'book'}\n" + "{'t-shirt', 'book', 'mug'}\n" ] } ], @@ -104,7 +106,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -113,7 +115,7 @@ "3" ] }, - "execution_count": 3, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -126,14 +128,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "75.0\n" + "60.0\n" ] } ], @@ -144,26 +146,26 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "('3', '75.0')\n" + "(3, 60.0)\n" ] } ], "source": [ "order_status = ()\n", - "order_status = order_status + (\"3\", \"75.0\")\n", + "order_status = order_status + (3, 60.0)\n", "print(order_status)" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -172,7 +174,7 @@ "text": [ "Order statistics:\n", "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 75.0\n" + "Percentage of Products Ordered: 60.0\n" ] } ], @@ -183,14 +185,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': 1, 'mug': 1, 'book': 1, 'keychain': 2}\n" + "{'t-shirt': 1, 'mug': 1, 'book': 1, 'hat': 2, 'keychain': 2}\n" ] } ], @@ -203,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -213,14 +215,16 @@ "t-shirt: 1\n", "mug: 1\n", "book: 1\n", + "hat: 2\n", "keychain: 2\n" ] } ], "source": [ - "print(\"t-shirt: \", inventory[\"book\"])\n", + "print(\"t-shirt: \", inventory[\"t-shirt\"])\n", "print(\"mug: \", inventory[\"mug\"])\n", "print(\"book: \", inventory[\"book\"])\n", + "print(\"hat: \", inventory[\"hat\"])\n", "print(\"keychain: \", inventory[\"keychain\"])" ] }