From 40be94f333bc9a5184d6258152f829a32c3ebbba Mon Sep 17 00:00:00 2001 From: Victoria Vasilieva Date: Mon, 27 Jan 2025 16:58:48 +0200 Subject: [PATCH 1/2] lab completed --- 1_variables_operators.ipynb | 438 ++++++++++++++++++++++++++++++------ 1 file changed, 372 insertions(+), 66 deletions(-) diff --git a/1_variables_operators.ipynb b/1_variables_operators.ipynb index 5d0ce83..38802bf 100644 --- a/1_variables_operators.ipynb +++ b/1_variables_operators.ipynb @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -382,9 +382,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Float - stores decimal numbers. By default, Python interprets any number that includes a decimal point as a double precision floating point number. Like some other programming languages, in Python there is not much difference between float and double except that float is in-built in Python, while double is imported from a library called NumPy.\n", + "We will talk about the libraries in detail later.\n", + "Hello\n", + "There!\n" + ] + }, + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Multiple line string\n", "x = '''Float - stores decimal numbers. By default, Python interprets any number that includes a decimal point as a double precision floating point number. Like some other programming languages, in Python there is not much difference between float and double except that float is in-built in Python, while double is imported from a library called NumPy.\n", @@ -545,72 +566,151 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# You can try and test these operators as shown below" + "# You can try and test these operators as shown below\n", + "x = 2\n", + "y = 3" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x+y" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "-1" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x-y" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x*y" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x/y" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x%y # Gives the remainder" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x**y # 'y' times multiplication of 'x'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x // y # Rounds off the result to the lower integer value on the number line" ] @@ -631,9 +731,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'name' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[54], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mname\u001b[49m \u001b[38;5;241m+\u001b[39m surname\n", + "\u001b[1;31mNameError\u001b[0m: name 'name' is not defined" + ] + } + ], "source": [ "name + surname" ] @@ -731,9 +843,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "13\n" + ] + } + ], "source": [ "x = 10\n", "x+=3\n", @@ -749,9 +869,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n" + ] + } + ], "source": [ "x = 10\n", "x-=3\n", @@ -785,9 +913,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.3333333333333335\n" + ] + } + ], "source": [ "x = 10\n", "x/=3\n", @@ -991,22 +1127,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x < 5 and y < 10 # Returns False since both conditions are False" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x > 5 and y < 20 # Returns True since both conditions are True" ] @@ -1153,9 +1311,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "\n" + ] + } + ], "source": [ "num_float = 3.14 # This is a float\n", "num_int = int(num_float)\n", @@ -1308,7 +1475,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -1327,10 +1494,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "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))\n" + ] }, { "cell_type": "markdown", @@ -1344,7 +1521,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#x1 is a float and x2 is a str" + ] }, { "cell_type": "markdown", @@ -1358,7 +1537,16 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "x1 -x3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It causes an error because the data types for the subtraction are incompatible" + ] }, { "cell_type": "markdown", @@ -1372,7 +1560,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#x4 is a bool and x5 is a str" + ] }, { "cell_type": "markdown", @@ -1383,10 +1573,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "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[37], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mx5\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mx4\u001b[49m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'bool'" + ] + } + ], + "source": [ + "x5 - x4" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It causes an error because the data types for the subtraction are incompatible" + ] }, { "cell_type": "markdown", @@ -1427,10 +1638,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 6\n", + " \n" + ] + } + ], + "source": [ + "x1 = input(\"Please enter an integer number: \")\n", + "x2 = input(\"Please enter another integer number: \")\n", + "print(x1, x2)\n", + "print (type(x1), type(x2))" + ] }, { "cell_type": "markdown", @@ -1441,10 +1666,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 6\n", + " \n" + ] + } + ], + "source": [ + "x1 =int(x1)\n", + "x2 = int(x2)\n", + "print(x1, x2)\n", + "print (type(x1), type(x2))" + ] }, { "cell_type": "markdown", @@ -1466,10 +1705,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n", + "True\n" + ] + } + ], + "source": [ + "x1 = 10\n", + "x2 = 4\n", + "print(x1 == x2)\n", + "print(x1 > x2)\n", + "print (x2 > x1)\n", + "print (x1 != x2)\n", + "x3 = x1 - x2\n", + "x2 += x3\n", + "print (x1 == x2)" + ] }, { "cell_type": "markdown", @@ -1482,10 +1743,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, john doe!\n" + ] + } + ], + "source": [ + "first_name = input(\"Please enter your first name: \")\n", + "last_name = input(\"Please enter your last name: \")\n", + "print ( \"Hello, \"+ first_name + ' ' + last_name + '!')" + ] }, { "cell_type": "markdown", @@ -1496,7 +1769,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -1544,9 +1817,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x is y" ] @@ -1568,9 +1852,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x is not y" ] @@ -1600,7 +1895,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ @@ -1625,9 +1920,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a in b" ] @@ -1666,7 +1972,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -1680,7 +1986,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.3" } }, "nbformat": 4, From 700d3baaccf428e0436f84618e596c55daa2aa6a Mon Sep 17 00:00:00 2001 From: Victoria Vasilieva Date: Mon, 27 Jan 2025 17:05:12 +0200 Subject: [PATCH 2/2] lab completed --- 1_variables_operators.ipynb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/1_variables_operators.ipynb b/1_variables_operators.ipynb index 38802bf..56df4ed 100644 --- a/1_variables_operators.ipynb +++ b/1_variables_operators.ipynb @@ -731,22 +731,23 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 56, "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'name' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[54], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mname\u001b[49m \u001b[38;5;241m+\u001b[39m surname\n", - "\u001b[1;31mNameError\u001b[0m: name 'name' is not defined" - ] + "data": { + "text/plain": [ + "'LisaDawson'" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ + "name = \"Lisa\"\n", + "surname = \"Dawson\"\n", "name + surname" ] },