From 09303c33737acb481d11ee1c4a066e09391965fa Mon Sep 17 00:00:00 2001 From: foscanit Date: Mon, 16 Oct 2023 19:22:39 +0200 Subject: [PATCH] =?UTF-8?q?[Cl=C3=A0udia=20Pintos]=20lab-errhand-listcomp?= =?UTF-8?q?=20tambi=C3=A9n=20sin=20bonus=20:(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- your-code/main.ipynb | 479 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 406 insertions(+), 73 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index f3bde01..c0c9a42 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -24,11 +24,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "id": "630d7e4d", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import math\n", + "import sys" + ] }, { "cell_type": "markdown", @@ -46,6 +49,25 @@ "metadata": {}, "source": [] }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3825e1d1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], + "source": [ + "square = [i**2 for i in range(1,21)]\n", + "print(square)" + ] + }, { "cell_type": "markdown", "id": "b421e0cb", @@ -59,11 +81,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "c047115a", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000]\n" + ] + } + ], + "source": [ + "sqrt = [i**2 for i in range(1, 101)]\n", + "print(sqrt)" + ] }, { "cell_type": "markdown", @@ -77,11 +110,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "e23d87ea", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0]\n" + ] + } + ], + "source": [ + "my_list = [i for i in range(-10,1)]\n", + "print(my_list)" + ] }, { "cell_type": "markdown", @@ -95,11 +139,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "d8d1c865", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]\n" + ] + } + ], + "source": [ + "odds = [i for i in range(1, 101) if i % 2 != 0]\n", + "print(odds)" + ] }, { "cell_type": "markdown", @@ -112,11 +167,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "6a9cfb8c", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 182, 189, 196, 203, 210, 217, 224, 231, 238, 245, 252, 259, 266, 273, 280, 287, 294, 301, 308, 315, 322, 329, 336, 343, 350, 357, 364, 371, 378, 385, 392, 399, 406, 413, 420, 427, 434, 441, 448, 455, 462, 469, 476, 483, 490, 497, 504, 511, 518, 525, 532, 539, 546, 553, 560, 567, 574, 581, 588, 595, 602, 609, 616, 623, 630, 637, 644, 651, 658, 665, 672, 679, 686, 693, 700, 707, 714, 721, 728, 735, 742, 749, 756, 763, 770, 777, 784, 791, 798, 805, 812, 819, 826, 833, 840, 847, 854, 861, 868, 875, 882, 889, 896, 903, 910, 917, 924, 931, 938, 945, 952, 959, 966, 973, 980, 987, 994]\n" + ] + } + ], + "source": [ + "divisible_by_seven = [i for i in range(1,1001) if i % 7 == 0]\n", + "print(divisible_by_seven)" + ] }, { "cell_type": "markdown", @@ -141,11 +207,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "d5fc7426", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['F', 'n', 'd', ' ', 'l', 'l', ' ', 'f', ' ', 't', 'h', ' ', 'w', 'r', 'd', 's', ' ', 'n', ' ', ' ', 's', 't', 'r', 'n', 'g', ' ', 't', 'h', 't', ' ', 'r', ' ', 'm', 'n', 's', 'y', 'l', 'l', 'b', 'c']\n" + ] + } + ], + "source": [ + "teststring = 'Find all of the words in a string that are monosyllabic'\n", + "vowels = \"aeiouAEIOU\"\n", + "non_vowels = [i for i in teststring if i not in vowels]\n", + "print(non_vowels) " + ] }, { "cell_type": "markdown", @@ -160,11 +239,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "3a43399c", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'Q', 'B', 'F', 'J', 'O', 'T', 'L', 'D']\n" + ] + } + ], + "source": [ + "string_2 = \"The Quick Brown Fox Jumped Over The Lazy Dog\"\n", + "\n", + "capital_letters = [i for i in string_2 if i.isupper() == True]\n", + "print(capital_letters)" + ] }, { "cell_type": "markdown", @@ -179,11 +271,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "3ddb68df", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thqckbrwnfxjmpdvrthlzydg\n" + ] + } + ], + "source": [ + "teststring = \"The quick brown fox jumped over the lazy dog\"\n", + "vowels = \"aeiouAEIOU\"\n", + "non_vowels = [i for i in teststring if i not in vowels and i.isspace() != True]\n", + "print(''.join(non_vowels)) " + ] }, { "cell_type": "markdown", @@ -201,11 +306,25 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "22bb13eb", + "execution_count": 1, + "id": "dc9c0092", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['week-2', 'images', 'example', 'datasets', 'troubleshooting', 'week-1', '.git', 'cheatsheet', 'faq-and-examples']\n" + ] + } + ], + "source": [ + "import os\n", + "path = \"/Users/usuari/Desktop/Ironhack/BOOTCAMP/lectures\"\n", + "\n", + "files = [folder for folder in os.listdir(path) if os.path.isdir(os.path.join(path, folder))]\n", + "print(files)" + ] }, { "cell_type": "markdown", @@ -220,11 +339,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "120b29bd", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[3, 5, 10, 63, 50, 73, 34, 99, 24, 26], [68, 8, 9, 60, 58, 36, 92, 20, 86, 64], [83, 57, 80, 17, 64, 30, 87, 48, 77, 61], [99, 10, 14, 62, 68, 27, 87, 23, 88, 35]]\n" + ] + } + ], + "source": [ + "# Option 1\n", + "import random as rd\n", + "\n", + "random_lists = [rd.sample(range(100), k=10)] + [rd.sample(range(100), k=10)] + [rd.sample(range(100), k=10)] + [rd.sample(range(100), k=10)]\n", + "print(random_lists)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "58bc502a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[22, 82, 85, 12, 64, 55, 58, 1, 72, 6], [20, 79, 90, 3, 67, 97, 21, 61, 52, 3], [79, 69, 89, 48, 51, 12, 8, 8, 100, 33], [54, 96, 31, 22, 35, 71, 73, 77, 60, 93]]\n" + ] + } + ], + "source": [ + "# Option 2\n", + "\n", + "random_lists = [[rd.randint(0,100) for _ in range(10)] for _ in range(4)]\n", + "print(random_lists)" + ] }, { "cell_type": "markdown", @@ -238,7 +392,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "b3afebb7", "metadata": {}, "outputs": [], @@ -248,11 +402,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "b6bcef37", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ] + } + ], + "source": [ + "flatten_list = [j for i in list_of_lists for j in i]\n", + "print(flatten_list)" + ] }, { "cell_type": "markdown", @@ -267,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "7087f44e", "metadata": {}, "outputs": [], @@ -279,11 +444,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "a932aff5", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[40.0, 20.0, 10.0, 30.0, 20.0, 20.0, 20.0, 20.0, 20.0, 30.0, 20.0, 30.0, 20.0, 30.0, 50.0, 10.0, 30.0, 20.0, 20.0, 20.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]\n" + ] + } + ], + "source": [ + "floats = [float(j) for i in list_of_lists for j in i]\n", + "print(floats)" + ] }, { "cell_type": "markdown", @@ -295,22 +471,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "b5980ab4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for ** or pow(): 'str' and 'int'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[23], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mc\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m (i\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m)\n", + "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'str' and 'int'" + ] + } + ], "source": [ "for i in ['a','b','c']:\n", - " print i**2" + " print (i**2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "3605fc78", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error: Cannot square a string, a\n", + "Error: Cannot square a string, b\n", + "Error: Cannot square a string, c\n" + ] + } + ], + "source": [ + "for i in ['a', 'b', 'c']:\n", + " try:\n", + " print(i**2)\n", + " except TypeError:\n", + " print(f\"Error: Cannot square a string, {i}\") " + ] }, { "cell_type": "markdown", @@ -326,10 +530,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "441acd1c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[28], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m\n\u001b[1;32m 2\u001b[0m y \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m----> 4\u001b[0m z \u001b[38;5;241m=\u001b[39m x\u001b[38;5;241m/\u001b[39my\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" + ] + } + ], "source": [ "x = 5\n", "y = 0\n", @@ -339,11 +555,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "976fec9f", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error: Cannot divide a number by zero, y = 0\n" + ] + } + ], + "source": [ + "x = 5\n", + "y = 0\n", + "try:\n", + " z = x/y\n", + " print(z)\n", + "except ZeroDivisionError:\n", + " print(f\"Error: Cannot divide a number by zero, y = {y}\")\n" + ] }, { "cell_type": "markdown", @@ -357,10 +589,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "783a8224", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[33], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m abc\u001b[38;5;241m=\u001b[39m[\u001b[38;5;241m10\u001b[39m,\u001b[38;5;241m20\u001b[39m,\u001b[38;5;241m20\u001b[39m]\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(abc[\u001b[38;5;241m3\u001b[39m])\n", + "\u001b[0;31mIndexError\u001b[0m: list index out of range" + ] + } + ], "source": [ "abc=[10,20,20]\n", "print(abc[3])" @@ -368,11 +612,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "id": "cfcf15f0", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error: list index out of range\n" + ] + } + ], + "source": [ + "abc = [10, 20, 30]\n", + "try:\n", + " print(abc[3])\n", + "except IndexError:\n", + " print(\"Error: list index out of range\")" + ] }, { "cell_type": "markdown", @@ -388,11 +646,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "3c1f141b", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please insert a number, a\n", + "Error: That is not a number\n" + ] + } + ], + "source": [ + "try:\n", + " n1 = int(input(\"Please insert a number, \"))\n", + " n2 = int(input(\"Please insert a number, \"))\n", + " print(n1/n2)\n", + "except ValueError:\n", + " print(f\"Error: That is not a number\")\n", + "except ZeroDivisionError:\n", + " print(f\"Error: Cannot divide a number by zero, n2 = {y}\")" + ] }, { "cell_type": "markdown", @@ -429,11 +705,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "id": "5a1cb361", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error: file not found\n" + ] + } + ], + "source": [ + "try:\n", + " f = open('testfile', 'r')\n", + " f.write('Test write this')\n", + "except FileNotFoundError:\n", + " print(\"Error: file not found\")" + ] }, { "cell_type": "markdown", @@ -466,6 +756,33 @@ " i = int(s.strip())\n" ] }, + { + "cell_type": "code", + "execution_count": 48, + "id": "82512e3f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error: file not found\n" + ] + } + ], + "source": [ + "try:\n", + " fp = open('myfile.txt')\n", + " line = f.readline()\n", + " i = int(s.strip())\n", + "except IndentationError:\n", + " print(\"Error: unexpected indent\")\n", + "except FileNotFoundError:\n", + " print(\"Error: file not found\")\n", + "except ValueError:\n", + " print(\"Value Error\")" + ] + }, { "cell_type": "markdown", "id": "d695245b", @@ -481,20 +798,20 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 50, "id": "3f043ef6", "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'sys' is not defined", + "ename": "AssertionError", + "evalue": "Function can only run on Linux systems.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'linux'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplatform\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Function can only run on Linux systems.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Doing something.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mlinux_interaction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m\u001b[0m in \u001b[0;36mlinux_interaction\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mlinux_interaction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'linux'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplatform\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Function can only run on Linux systems.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Doing something.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mlinux_interaction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'sys' is not defined" + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[50], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlinux\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m sys\u001b[38;5;241m.\u001b[39mplatform), \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFunction can only run on Linux systems.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDoing something.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 4\u001b[0m linux_interaction()\n", + "Cell \u001b[0;32mIn[50], line 2\u001b[0m, in \u001b[0;36mlinux_interaction\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlinux_interaction\u001b[39m():\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlinux\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m sys\u001b[38;5;241m.\u001b[39mplatform), \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFunction can only run on Linux systems.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDoing something.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[0;31mAssertionError\u001b[0m: Function can only run on Linux systems." ] } ], @@ -507,11 +824,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "id": "1643bbed", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function can only run on Linux systems\n" + ] + } + ], + "source": [ + "try:\n", + " def linux_interaction():\n", + " assert ('linux' in sys.platform), \"Function can only run on Linux systems.\"\n", + " print('Doing something.')\n", + " linux_interaction()\n", + "except AssertionError:\n", + " print(\"Function can only run on Linux systems\")" + ] }, { "cell_type": "markdown", @@ -622,9 +955,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironhack", "language": "python", - "name": "python3" + "name": "ironhack" }, "language_info": { "codemirror_mode": { @@ -636,7 +969,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.5" }, "toc": { "base_numbering": 1,