From 8e49df22f0c45c968e7bfbef2899c322d9e4b678 Mon Sep 17 00:00:00 2001 From: Martina Rivero Date: Wed, 11 Oct 2023 08:48:40 +0200 Subject: [PATCH 1/2] Martina_Rivero_Challenge1 --- your-code/challenge-1.ipynb | 195 ++++++++++++++++++++++++++++++------ 1 file changed, 162 insertions(+), 33 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 3ff7f9b..1afc311 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -14,11 +14,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "tup = (\"I\", )\n", + "\n", + "\n", + "\n" ] }, { @@ -32,11 +35,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(type(single_tuple))\n" ] }, { @@ -54,13 +65,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'tuple' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[59], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m tup\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ - "# Your code here\n", + "tup.append(\"r\")\n", "\n", - "# Your explanation here\n" + "Elements cannot be appended to tuples directly. \n", + "In order to append elements to a tuple, they have to be converted into a list.\n", + "\n" ] }, { @@ -80,13 +105,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The tuple is: ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n" + "list_of_a_tuple = list(tup)\n", + "list_of_a_tuple.append(\"r\")\n", + "list_of_a_tuple.append(\"o\")\n", + "list_of_a_tuple.append(\"n\")\n", + "list_of_a_tuple.append(\"h\")\n", + "list_of_a_tuple.append(\"a\")\n", + "list_of_a_tuple.append(\"c\")\n", + "list_of_a_tuple.append(\"k\")\n", + "new_tuple = tuple(list_of_a_tuple)\n", + "print(\"The tuple is:\", new_tuple)\n" ] }, { @@ -104,11 +144,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tup1 is ('I', 'r', 'o', 'n')\n", + "Tup2 is ('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup1 = new_tuple[0:4]\n", + "tup2 = new_tuple[-4:]\n", + "\n", + "print(\"Tup1 is\", tup1)\n", + "print(\"Tup2 is\", tup2)\n" ] }, { @@ -122,11 +175,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup3 = tup1 + tup2\n", + "print(tup3)" ] }, { @@ -138,11 +200,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number of elements of tup1 is 4\n", + "The number of elements of tup2 is 4\n", + "The number of elements of tup3 is 8\n" + ] + } + ], "source": [ - "# Your code here\n" + "count_tup1 = len(tup1)\n", + "count_tup2 = len(tup2)\n", + "print(\"The number of elements of tup1 is\", count_tup1)\n", + "print(\"The number of elements of tup2 is\", count_tup2)\n", + "count_tup3 = len(tup3)\n", + "print(\"The number of elements of tup3 is\", count_tup3)" ] }, { @@ -154,11 +231,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 103, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The index number of 'h' in tup3 is 4\n" + ] + } + ], "source": [ - "# Your code here\n" + "x = tup3.index(\"h\")\n", + "print(\"The index number of 'h' in tup3 is\", x)\n" ] }, { @@ -178,11 +264,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 124, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here\n" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "for i in letters:\n", + " if i in tup3:\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + " " ] }, { @@ -203,12 +307,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 151, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Repeated letter is a , 1 times\n", + " \n", + "Repeated letter is c , 2 times\n", + " \n", + " \n" + ] + } + ], "source": [ - "# Your code here\n" + "count = 0\n", + "for i in letters:\n", + " if i in tup3:\n", + " count +=1\n", + " print(\"Repeated letter is\", i, \",\", count, \"times\")\n", + " else:\n", + " print(\" \")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -227,7 +356,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.5" }, "toc": { "base_numbering": 1, From 8d08275bcf542a119cd878b516845aa2f7465d94 Mon Sep 17 00:00:00 2001 From: Martina Rivero Date: Wed, 11 Oct 2023 08:51:31 +0200 Subject: [PATCH 2/2] Martina_Rivero_Challenge1 --- your-code/challenge-2.ipynb | 280 ++++++++++++++++++++++++++++-------- 1 file changed, 221 insertions(+), 59 deletions(-) diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 49072f2..cdd6c86 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -47,11 +47,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[71, 53, 0, 6, 54, 81, 19, 46, 5, 9, 99, 11, 75, 84, 72, 17, 7, 93, 52, 90, 32, 33, 55, 79, 87, 37, 98, 31, 50, 92, 3, 78, 83, 82, 25, 26, 34, 8, 2, 12, 28, 40, 65, 38, 91, 21, 45, 77, 22, 13, 51, 73, 4, 62, 27, 80, 18, 97, 44, 66, 56, 95, 23, 69, 57, 59, 67, 70, 39, 14, 30, 61, 41, 96, 63, 85, 60, 47, 10, 49]\n" + ] + } + ], "source": [ - "# Your code here\n" + "import random\n", + "sample_list_1 = random.sample(range(100), k=80)\n", + "print(sample_list_1)\n" ] }, { @@ -63,11 +73,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], "source": [ - "# Your code here\n" + "set1 = set(sample_list_1)\n", + "count_set1 = len(set1)\n", + "print(count_set1)" ] }, { @@ -86,11 +106,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[67, 91, 99, 16, 6, 14, 61, 58, 76, 70, 70, 2, 54, 49, 23, 90, 11, 8, 35, 66, 90, 94, 77, 66, 11, 26, 12, 44, 60, 88, 24, 67, 2, 7, 74, 41, 60, 79, 87, 54, 40, 68, 26, 9, 7, 7, 18, 56, 4, 76, 20, 69, 6, 71, 69, 87, 70, 34, 89, 94, 0, 5, 45, 60, 97, 21, 69, 24, 22, 37, 35, 1, 52, 62, 85, 15, 32, 1, 91, 44]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_2 = [random.choice(range(100)) for i in range(80)]\n", + "print(sample_list_2)\n" ] }, { @@ -102,11 +131,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "56\n" + ] + } + ], "source": [ - "# Your code here\n" + "set2 = set(sample_list_2)\n", + "count_set2 = len(set2)\n", + "print(count_set2)\n" ] }, { @@ -118,11 +157,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 10, 13, 17, 19, 25, 27, 28, 30, 31, 33, 38, 39, 46, 47, 50, 51, 53, 55, 57, 59, 63, 65, 72, 73, 75, 78, 80, 81, 82, 83, 84, 92, 93, 95, 96, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set3 = set1.difference(set2)\n", + "print(set3)" ] }, { @@ -134,11 +182,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 35, 68, 74, 76, 15, 16, 20, 24, 89, 58, 88, 94}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set4 = set2.difference(set1)\n", + "print(set4)\n" ] }, { @@ -150,11 +207,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 4, 5, 6, 7, 8, 9, 11, 12, 14, 18, 21, 22, 23, 26, 32, 34, 37, 40, 41, 44, 45, 49, 52, 54, 56, 60, 61, 62, 66, 67, 69, 70, 71, 77, 79, 85, 87, 90, 91, 97, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set5 = set1.intersection(set2)\n", + "print(set5)\n" ] }, { @@ -186,11 +252,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "len(set1) == len(set3) + len(set4) + len(set5) - len(set2) + len(set5)\n" ] }, { @@ -202,11 +279,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6 = set()\n" ] }, { @@ -218,11 +295,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, 67, 69, 70, 71, 72, 73, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 90, 91, 92, 93, 95, 96, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6.update(set3)\n", + "set6.update(set5)\n", + "\n", + "print(set6)" ] }, { @@ -234,11 +322,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1 == set6\n" ] }, { @@ -250,11 +349,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set2.issubset(set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set3.issubset(set1)" ] }, { @@ -268,11 +398,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99}\n", + "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99}\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set7 = set3.union(set4, set5)\n", + "set8 = set1.union(set2)\n", + "\n", + "print(set7)\n", + "print(set8)\n", + "\n", + "set7 == set8" ] }, { @@ -284,11 +439,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, 67, 69, 70, 71, 72, 73, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 90, 91, 92, 93, 95, 96, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "x = set1.pop()\n", + "print(set1)" ] }, { @@ -307,9 +471,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Your code here\n" - ] + "source": [] } ], "metadata": { @@ -328,7 +490,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.5" }, "nbTranslate": { "displayLangs": [