diff --git a/your-code/main.ipynb b/your-code/main.ipynb
index f3bde01..3f84bbe 100644
--- a/your-code/main.ipynb
+++ b/your-code/main.ipynb
@@ -24,11 +24,18 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 189,
"id": "630d7e4d",
"metadata": {},
"outputs": [],
- "source": []
+ "source": [
+ "import pandas as pd\n",
+ "import math as m\n",
+ "import numpy as np\n",
+ "import random as rd\n",
+ "from functools import reduce\n",
+ "import sys\n"
+ ]
},
{
"cell_type": "markdown",
@@ -46,6 +53,25 @@
"metadata": {},
"source": []
},
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "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": [
+ "calculate_sqrt = [nums ** 2 for nums in range(1, 21)]\n",
+ "\n",
+ "print(calculate_sqrt)"
+ ]
+ },
{
"cell_type": "markdown",
"id": "b421e0cb",
@@ -59,11 +85,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"id": "c047115a",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[1.0, 1.4142135623730951, 1.7320508075688772, 2.0, 2.23606797749979, 2.449489742783178, 2.6457513110645907, 2.8284271247461903, 3.0, 3.1622776601683795, 3.3166247903554, 3.4641016151377544, 3.605551275463989, 3.7416573867739413, 3.872983346207417, 4.0, 4.123105625617661, 4.242640687119285, 4.358898943540674, 4.47213595499958, 4.58257569495584, 4.69041575982343, 4.795831523312719, 4.898979485566356, 5.0, 5.0990195135927845, 5.196152422706632, 5.291502622129181, 5.385164807134504, 5.477225575051661, 5.5677643628300215, 5.656854249492381, 5.744562646538029, 5.830951894845301, 5.916079783099616, 6.0, 6.082762530298219, 6.164414002968976, 6.244997998398398, 6.324555320336759, 6.4031242374328485, 6.48074069840786, 6.557438524302, 6.6332495807108, 6.708203932499369, 6.782329983125268, 6.855654600401044, 6.928203230275509, 7.0, 7.0710678118654755, 7.14142842854285, 7.211102550927978, 7.280109889280518, 7.3484692283495345, 7.416198487095663, 7.483314773547883, 7.54983443527075, 7.615773105863909, 7.681145747868608, 7.745966692414834, 7.810249675906654, 7.874007874011811, 7.937253933193772, 8.0, 8.06225774829855, 8.12403840463596, 8.18535277187245, 8.246211251235321, 8.306623862918075, 8.366600265340756, 8.426149773176359, 8.48528137423857, 8.54400374531753, 8.602325267042627, 8.660254037844387, 8.717797887081348, 8.774964387392123, 8.831760866327848, 8.888194417315589, 8.94427190999916, 9.0, 9.055385138137417, 9.1104335791443, 9.16515138991168, 9.219544457292887, 9.273618495495704, 9.327379053088816, 9.38083151964686, 9.433981132056603, 9.486832980505138, 9.539392014169456, 9.591663046625438, 9.643650760992955, 9.695359714832659, 9.746794344808963, 9.797958971132712, 9.848857801796104, 9.899494936611665, 9.9498743710662, 10.0]\n"
+ ]
+ }
+ ],
+ "source": [
+ "sqrt = [m.sqrt(nums) for nums in range(1, 101)]\n",
+ "print(sqrt)"
+ ]
},
{
"cell_type": "markdown",
@@ -77,11 +114,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 26,
"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 = [nums for nums in range(-10, 1)]\n",
+ "print(my_list)"
+ ]
},
{
"cell_type": "markdown",
@@ -95,11 +143,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 28,
"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 = [nums for nums in range(1, 101) if nums % 2 !=0]\n",
+ "print(odds)"
+ ]
},
{
"cell_type": "markdown",
@@ -112,11 +171,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 30,
"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]\n"
+ ]
+ }
+ ],
+ "source": [
+ "divisible_by_seven = [nums for nums in range(1, 101) if nums % 7 ==0]\n",
+ "print(divisible_by_seven)"
+ ]
},
{
"cell_type": "markdown",
@@ -129,24 +199,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "id": "43b38bd3",
+ "execution_count": 49,
+ "id": "d5fc7426",
"metadata": {},
- "outputs": [],
+ "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": [
"# You can use the following test string but feel free to modify at your convenience\n",
"\n",
- "teststring = 'Find all of the words in a string that are monosyllabic'"
+ "teststring = 'Find all of the words in a string that are monosyllabic'\n",
+ "\n",
+ "vowels = \"AEIOUaeiou\"\n",
+ "non_vowels = [char for char in teststring if char not in vowels and char.isalpha()]\n",
+ " \n",
+ "print(non_vowels)"
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "d5fc7426",
- "metadata": {},
- "outputs": [],
- "source": []
- },
{
"cell_type": "markdown",
"id": "277d491e",
@@ -160,11 +235,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 40,
"id": "3a43399c",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['T', 'Q', 'B', 'F', 'J', 'O', 'T', 'L', 'D']\n"
+ ]
+ }
+ ],
+ "source": [
+ "sentence = 'The Quick Brown Fox Jumped Over The Lazy Dog'\n",
+ "capital_letters = [letters for letters in sentence if letters.isupper()]\n",
+ "print(capital_letters)"
+ ]
},
{
"cell_type": "markdown",
@@ -179,11 +266,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 48,
"id": "3ddb68df",
"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": [
+ "sentence = 'The Quick Brown Fox Jumped Over The Lazy Dog'\n",
+ "\n",
+ "vowels = \"AEIOUaeiou\"\n",
+ "consonants = [char for char in teststring if char.isalpha() and char not in vowels]\n",
+ "\n",
+ "print(consonants)"
+ ]
},
{
"cell_type": "markdown",
@@ -201,11 +303,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 162,
"id": "22bb13eb",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['README.md', 'cheatsheet', 'datasets', 'example', 'faq-and-examples', 'images', 'troubleshooting', 'week-1', 'week-2']\n"
+ ]
+ }
+ ],
+ "source": [
+ "file_1 = !ls ../../lectures\n",
+ "file = [i for i in file_1]\n",
+ "print(file)"
+ ]
},
{
"cell_type": "markdown",
@@ -220,11 +334,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 119,
"id": "120b29bd",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[[43, 77, 67, 84, 95, 21, 97, 76, 49, 96], [59, 2, 94, 44, 100, 79, 37, 83, 70, 17], [60, 44, 5, 40, 78, 45, 21, 58, 66, 76], [85, 40, 86, 73, 64, 75, 15, 40, 94, 24]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "random_lists = [[rd.randint(0, 100) for i in range(10)] for _ in range(4)]\n",
+ "\n",
+ "print(random_lists)\n"
+ ]
},
{
"cell_type": "markdown",
@@ -238,7 +364,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 73,
"id": "b3afebb7",
"metadata": {},
"outputs": [],
@@ -248,11 +374,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 75,
"id": "b6bcef37",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 7, 8, 9, 7, 8, 9, 7, 8, 9]\n"
+ ]
+ }
+ ],
+ "source": [
+ "flatten_list = [nums_2 for nums in list_of_lists for nums_1 in nums for nums_2 in nums]\n",
+ "print(flatten_list)"
+ ]
},
{
"cell_type": "markdown",
@@ -267,7 +404,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 77,
"id": "7087f44e",
"metadata": {},
"outputs": [],
@@ -277,6 +414,26 @@
"['100', '100', '100', '100']]"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 138,
+ "id": "9023ce62",
+ "metadata": {},
+ "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(a) for i in list_of_lists for a in i]\n",
+ "\n",
+ "print(floats)"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -295,10 +452,19 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 146,
"id": "b5980ab4",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "Missing parentheses in call to 'print'. Did you mean print(...)? (3439384179.py, line 2)",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;36m Cell \u001b[1;32mIn[146], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m print i**2\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m Missing parentheses in call to 'print'. Did you mean print(...)?\n"
+ ]
+ }
+ ],
"source": [
"for i in ['a','b','c']:\n",
" print i**2"
@@ -306,11 +472,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "id": "3605fc78",
+ "execution_count": 147,
+ "id": "a09ec210",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a cannot be squared\n",
+ "b cannot be squared\n",
+ "c cannot be squared\n"
+ ]
+ }
+ ],
+ "source": [
+ "for i in ['a','b','c']:\n",
+ " try:\n",
+ " print (i**2)\n",
+ " except:\n",
+ " print (f\"{i} cannot be squared\")"
+ ]
},
{
"cell_type": "markdown",
@@ -326,10 +508,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 148,
"id": "441acd1c",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "ZeroDivisionError",
+ "evalue": "division by zero",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32mc:\\Users\\Felix\\Documents\\Ironhack\\lab-errhand-listcomp\\your-code\\main.ipynb Cell 36\u001b[0m line \u001b[0;36m4\n\u001b[0;32m 1\u001b[0m x \u001b[39m=\u001b[39m \u001b[39m5\u001b[39m\n\u001b[0;32m 2\u001b[0m y \u001b[39m=\u001b[39m \u001b[39m0\u001b[39m\n\u001b[1;32m----> 4\u001b[0m z \u001b[39m=\u001b[39m x\u001b[39m/\u001b[39;49my\n",
+ "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero"
+ ]
+ }
+ ],
"source": [
"x = 5\n",
"y = 0\n",
@@ -339,11 +533,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 161,
"id": "976fec9f",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Division by zero is not posible\n"
+ ]
+ }
+ ],
+ "source": [
+ "try:\n",
+ " print(z = x/y)\n",
+ "except:\n",
+ " print(\"Division by zero is not posible\")"
+ ]
},
{
"cell_type": "markdown",
@@ -368,11 +575,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 163,
"id": "cfcf15f0",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The index is out of range\n"
+ ]
+ }
+ ],
+ "source": [
+ "try:\n",
+ " print(abc[3])\n",
+ "except:\n",
+ " print(\"The index is out of range\")"
+ ]
},
{
"cell_type": "markdown",
@@ -388,11 +608,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 182,
"id": "3c1f141b",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Input entered is not a number\n"
+ ]
+ }
+ ],
+ "source": [
+ "dividend = input(\"Enter the number you want to divide \")\n",
+ "divisor = input(\"Enter the number the divisor\")\n",
+ "\n",
+ "try:\n",
+ " print(int(dividend)/int(divisor))\n",
+ "except ZeroDivisionError:\n",
+ " print(\"Division by zero is not posible\")\n",
+ "except ValueError:\n",
+ " print(\"Input entered is not a number\")"
+ ]
},
{
"cell_type": "markdown",
@@ -406,25 +644,24 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 184,
"id": "b73f824c",
"metadata": {},
"outputs": [
{
- "ename": "FileNotFoundError",
- "evalue": "[Errno 2] No such file or directory: 'testfile'",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
- "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'testfile'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Test write this'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'testfile'"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Directory or file not found\n"
]
}
],
"source": [
- "f = open('testfile','r')\n",
- "f.write('Test write this')"
+ "try:\n",
+ " f = open('testfile','r')\n",
+ " f.write('Test write this')\n",
+ "except:\n",
+ " print(\"Directory or file not found\")"
]
},
{
@@ -447,23 +684,31 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"id": "5f639ab1",
"metadata": {},
"outputs": [
{
- "ename": "IndentationError",
- "evalue": "unexpected indent (, line 2)",
- "output_type": "error",
- "traceback": [
- "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m line = f.readline()\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unexpected indent\n"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "File or Directory not found\n"
]
}
],
"source": [
- "fp = open('myfile.txt')\n",
+ "try:\n",
+ " fp = open('myfile.txt')\n",
" line = f.readline()\n",
- " i = int(s.strip())\n"
+ " i = int(s.strip())\n",
+ "except IndentationError:\n",
+ " print(\"Unexpected indentation\")\n",
+ " \n",
+ "except FileNotFoundError:\n",
+ " print(\"File or Directory not found\")\n",
+ "\n",
+ "except ValueError:\n",
+ " print(\"The data could not be convertable into int\")"
]
},
{
@@ -481,20 +726,20 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 191,
"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[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32mc:\\Users\\Felix\\Documents\\Ironhack\\lab-errhand-listcomp\\your-code\\main.ipynb Cell 49\u001b[0m line \u001b[0;36m4\n\u001b[0;32m 2\u001b[0m \u001b[39massert\u001b[39;00m (\u001b[39m'\u001b[39m\u001b[39mlinux\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m sys\u001b[39m.\u001b[39mplatform), \u001b[39m\"\u001b[39m\u001b[39mFunction can only run on Linux systems.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 3\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mDoing something.\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m----> 4\u001b[0m linux_interaction()\n",
+ "\u001b[1;32mc:\\Users\\Felix\\Documents\\Ironhack\\lab-errhand-listcomp\\your-code\\main.ipynb Cell 49\u001b[0m line \u001b[0;36m2\n\u001b[0;32m 1\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mlinux_interaction\u001b[39m():\n\u001b[1;32m----> 2\u001b[0m \u001b[39massert\u001b[39;00m (\u001b[39m'\u001b[39m\u001b[39mlinux\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m sys\u001b[39m.\u001b[39mplatform), \u001b[39m\"\u001b[39m\u001b[39mFunction can only run on Linux systems.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 3\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mDoing something.\u001b[39m\u001b[39m'\u001b[39m)\n",
+ "\u001b[1;31mAssertionError\u001b[0m: Function can only run on Linux systems."
]
}
],
@@ -505,6 +750,30 @@
"linux_interaction()"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 192,
+ "id": "f4ab2e62",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Function can only run on Linus 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 Linus systems\")"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -636,7 +905,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.13"
+ "version": "3.11.5"
},
"toc": {
"base_numbering": 1,