From 6322a639f87f24f754e090e58b5004cded8e2016 Mon Sep 17 00:00:00 2001 From: leonbts Date: Tue, 28 Jan 2025 01:00:07 +0100 Subject: [PATCH 1/2] Finished exercises --- 1_variables_operators.ipynb | 270 +++++++++++++++++++++++++++++++----- 1 file changed, 236 insertions(+), 34 deletions(-) diff --git a/1_variables_operators.ipynb b/1_variables_operators.ipynb index 5d0ce83..b039b05 100644 --- a/1_variables_operators.ipynb +++ b/1_variables_operators.ipynb @@ -1308,7 +1308,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -1327,10 +1327,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n" + ] + } + ], + "source": [ + "print(type(x1), type(x2), type(x3), type(x4), type(x5), type(x6))" + ] }, { "cell_type": "markdown", @@ -1344,7 +1354,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# x1 is a float and x3 is a string" + ] }, { "cell_type": "markdown", @@ -1358,7 +1370,10 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "x1-x3\n", + "# This will give an error because you cannot subtract a string from an integer" + ] }, { "cell_type": "markdown", @@ -1372,7 +1387,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# x4 is a boolean and x5 is a string" + ] }, { "cell_type": "markdown", @@ -1383,10 +1400,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for -: 'str' and 'bool'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[33], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mx5\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43mx4\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# This will give an error because you cannot subtract a string from a boolean\u001b[39;00m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'bool'" + ] + } + ], + "source": [ + "x5-x4\n", + "# This will give an error because you cannot subtract a string from a boolean" + ] }, { "cell_type": "markdown", @@ -1427,10 +1459,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5, 6\n" + ] + }, + { + "data": { + "text/plain": [ + "(str, str)" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1 = input(\"Please enter an integer number: \")\n", + "x2 = input(\"Please enter another integer number: \")\n", + "print(x1 + \", \" + x2)\n", + "type(x1), type(x2)" + ] }, { "cell_type": "markdown", @@ -1441,10 +1496,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "\n", + "6\n", + "\n" + ] + } + ], + "source": [ + "x1int = int(x1)\n", + "x2int = int(x2)\n", + "print(x1int)\n", + "print(type(x1int))\n", + "print(x2int)\n", + "print(type(x2int))" + ] }, { "cell_type": "markdown", @@ -1466,10 +1539,83 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1 == x2" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1 > x2" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1 < x2" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1 != x2" + ] }, { "cell_type": "markdown", @@ -1482,10 +1628,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, Leon Bittis!\n" + ] + } + ], + "source": [ + "first_name = input(\"Please enter your first name: \")\n", + "last_name = input(\"Please enter your last name: \")\n", + "print(\"Good Evening, \" + first_name + \" \" + last_name + \"!\")" + ] }, { "cell_type": "markdown", @@ -1496,7 +1654,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -1544,9 +1702,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x is y" ] @@ -1568,9 +1737,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x is not y" ] @@ -1600,7 +1780,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -1625,9 +1805,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a in b" ] @@ -1649,9 +1840,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a not in b" ] @@ -1666,7 +1868,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -1680,7 +1882,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.2" } }, "nbformat": 4, From 1f432727da8440081146f1b74117564bad65edd2 Mon Sep 17 00:00:00 2001 From: leonbts Date: Tue, 28 Jan 2025 01:03:27 +0100 Subject: [PATCH 2/2] Finished exercises --- 1_variables_operators.ipynb | 62 ++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/1_variables_operators.ipynb b/1_variables_operators.ipynb index b039b05..e33cf3f 100644 --- a/1_variables_operators.ipynb +++ b/1_variables_operators.ipynb @@ -1308,7 +1308,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -1327,14 +1327,14 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " \n" + " \n" ] } ], @@ -1351,7 +1351,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ @@ -1367,9 +1367,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for -: 'float' and 'str'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[55], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mx1\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43mx3\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# This will give an error because you cannot subtract a string from an integer\u001b[39;00m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'float' and 'str'" + ] + } + ], "source": [ "x1-x3\n", "# This will give an error because you cannot subtract a string from an integer" @@ -1384,7 +1396,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ @@ -1400,7 +1412,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 57, "metadata": {}, "outputs": [ { @@ -1410,7 +1422,7 @@ "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[33], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mx5\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43mx4\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# This will give an error because you cannot subtract a string from a boolean\u001b[39;00m\n", + "Cell \u001b[1;32mIn[57], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mx5\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43mx4\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# This will give an error because you cannot subtract a string from a boolean\u001b[39;00m\n", "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'bool'" ] } @@ -1459,14 +1471,14 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "5, 6\n" + "3, 7\n" ] }, { @@ -1475,7 +1487,7 @@ "(str, str)" ] }, - "execution_count": 40, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1496,16 +1508,16 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "5\n", + "3\n", "\n", - "6\n", + "7\n", "\n" ] } @@ -1539,7 +1551,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -1548,7 +1560,7 @@ "False" ] }, - "execution_count": 37, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -1559,7 +1571,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 61, "metadata": {}, "outputs": [ { @@ -1568,7 +1580,7 @@ "False" ] }, - "execution_count": 36, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -1579,7 +1591,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 62, "metadata": {}, "outputs": [ { @@ -1588,7 +1600,7 @@ "True" ] }, - "execution_count": 38, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -1599,7 +1611,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -1608,7 +1620,7 @@ "True" ] }, - "execution_count": 39, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -1628,14 +1640,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Hello, Leon Bittis!\n" + "Good Evening, Leon Bittis!\n" ] } ],