From 7a288f24f64a063010c264c6a98681ebdbfc58e5 Mon Sep 17 00:00:00 2001 From: elham Date: Sun, 5 Oct 2025 18:55:55 +0200 Subject: [PATCH 1/3] My Python exercises --- .../Basics/1_Numeric_Variable_Types.ipynb | 517 ++++++++++++++-- .../01_Python_Basics/Basics/2_Strings.ipynb | 579 ++++++++++++++++-- .../Basics/3_If_Statement.ipynb | 347 +++++++++-- .../01_Python_Basics/Basics/4_Loops.ipynb | 299 ++++++++- .../Data_Structures_in_Python/1_Lists.ipynb | 439 +++++++++++-- .../Data_Structures_in_Python/2_Sets.ipynb | 186 +++++- .../3_Mutability.ipynb | 285 ++++++++- .../4_Dictionaries.ipynb | 501 +++++++++++++-- .../5_Comprehension.ipynb | 165 ++++- .../1_Introduction_to_Functions.ipynb | 167 ++++- .../Functions/2_Function_Definitions.ipynb | 421 +++++++++++-- .../Functions/3_Calling_Functions.ipynb | 188 +++++- .../Functions/4_Functions_Challenge.ipynb | 272 +++++++- .../01_Python_Basics/requirements.txt | 2 + 14 files changed, 3943 insertions(+), 425 deletions(-) diff --git a/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb b/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb index 82530e84..d74ae397 100644 --- a/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb @@ -46,88 +46,165 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.429214Z", "start_time": "2020-06-30T11:34:51.418682Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "55" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "32 + 23" + "32 + 23\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.456179Z", "start_time": "2020-06-30T11:34:51.436541Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "-2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "19 - 21" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.503183Z", "start_time": "2020-06-30T11:34:51.463300Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "121" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "11 * 11" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.554866Z", "start_time": "2020-06-30T11:34:51.510152Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.375" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "12 / 32" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.565917Z", "start_time": "2020-06-30T11:34:51.558759Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "3 ** 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "4 + 6 * 5" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "(4 + 6) * 5" ] @@ -145,9 +222,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Floor division \n", "34 // 4" @@ -163,9 +251,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Modulo\n", "34 % 4" @@ -183,45 +282,100 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2.14" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "abs(2.14)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2.14" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "abs(-2.14)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "min(14, 21, 32, 11, 44, 23)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "44" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "max(14, 21, 32, 11, 44, 23)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3.142" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "round(3.14159265359, 3)" ] @@ -246,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.694614Z", @@ -261,42 +415,75 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.711513Z", "start_time": "2020-06-30T11:34:51.703416Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "b" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.723777Z", "start_time": "2020-06-30T11:34:51.714309Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a - 4" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.736043Z", "start_time": "2020-06-30T11:34:51.726241Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'HelloHelloHelloHelloHelloHelloHelloHello'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a * b" ] @@ -319,14 +506,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.753269Z", "start_time": "2020-06-30T11:34:51.738671Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a = a + 5\n", "a" @@ -381,7 +579,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.223748Z", @@ -389,14 +587,25 @@ }, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "14 # Int" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.302631Z", @@ -404,63 +613,118 @@ }, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "32.2" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "32.2 # Float" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.353655Z", "start_time": "2020-06-30T11:34:51.313466Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(5+6j)" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "complex(5, 6) # complex" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.379983Z", "start_time": "2020-06-30T11:34:51.361564Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(14)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.396272Z", "start_time": "2020-06-30T11:34:51.385142Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(82.6)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.410079Z", "start_time": "2020-06-30T11:34:51.399690Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "complex" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(complex(5, 6))" ] @@ -530,6 +794,30 @@ "6. `(21 / 3) % 2`" ] }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8.0 3.0 144 4 2.857142857142857 1.0\n" + ] + } + ], + "source": [ + "x1 = 19.0 - 11\n", + "x2 = 12 * 0.25\n", + "x3 = 12 ** 2\n", + "x4 = 25 // 6\n", + "x5 = (12 + 8) / 7\n", + "x6 = (21 / 3) % 2\n", + "\n", + "print(x1, x2, x3, x4, x5, x6)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -550,6 +838,36 @@ "What are the values of x and y after each line?" ] }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "82\n", + "30\n", + "112\n", + "109\n", + "8\n" + ] + } + ], + "source": [ + "x = 82\n", + "print(x)\n", + "y = 30\n", + "print(y)\n", + "x += y\n", + "print(x)\n", + "y = x - 3\n", + "print(y)\n", + "x -= y - 5\n", + "print(x)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -563,6 +881,66 @@ "3. `complex(-5, -10.2)`" ] }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(100.32)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "complex" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(complex(-5, -10.2))" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -575,10 +953,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27.666666666666668\n" + ] + } + ], + "source": [ + "p1 = 21 \n", + "p2 = 43\n", + "p3 = 19\n", + "p_mean = (p1 + p2 +p3)/ 3 \n", + "print(p_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "27.67\n" + ] + } + ], + "source": [ + "print (round(p_mean, 2))" + ] } ], "metadata": { @@ -597,7 +1006,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb b/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb index 50502e17..95b9b214 100644 --- a/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb @@ -132,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:16.315983Z", @@ -146,14 +146,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:16.520959Z", "start_time": "2020-02-03T15:12:16.516886Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string variable.'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable # my_str_variable holds the string that we put in it in the above cell. " ] @@ -170,28 +181,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:17.160652Z", "start_time": "2020-02-03T15:12:17.156894Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'My first stringMy second string'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'My first string' + 'My second string'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:17.391947Z", "start_time": "2020-02-03T15:12:17.388407Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Repeating stringRepeating stringRepeating string'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'Repeating string' * 3" ] @@ -206,28 +239,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.143676Z", "start_time": "2020-02-03T15:12:18.140185Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'My first string My second string'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'My first string' + ' ' + 'My second string'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.339653Z", "start_time": "2020-02-03T15:12:18.336299Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Repeating string Repeating string Repeating string '" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'Repeating string ' * 3" ] @@ -242,28 +297,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.726966Z", "start_time": "2020-02-03T15:12:18.723621Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Repeating string Repeating string Repeating string'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'Repeating string Repeating string Repeating string '.strip()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.916816Z", "start_time": "2020-02-03T15:12:18.912908Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Repeating string Repeating string Repeating string'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "' Repeating string Repeating string Repeating string '.strip()" ] @@ -280,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.338107Z", @@ -294,28 +371,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.524151Z", "start_time": "2020-02-03T15:12:19.520640Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is my string to play around with.'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.capitalize()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.719967Z", "start_time": "2020-02-03T15:12:19.716671Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'THIS IS MY STRING TO PLAY AROUND WITH.'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.upper()" ] @@ -323,45 +422,94 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.959612Z", "start_time": "2020-02-03T15:12:19.956274Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'this is my string to play around with.'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.lower()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:20.275946Z", "start_time": "2020-02-03T15:12:20.272448Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'this IS my flING to PLAY around WITH.'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.replace('STR', 'fl')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:20.525214Z", "start_time": "2020-02-03T15:12:20.521608Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['this', 'IS', 'my', 'STRING', 'to', 'PLAY', 'around', 'WITH.']" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.split()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "my_str_variable.strip" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -407,14 +555,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:15.822311Z", "start_time": "2020-02-03T15:44:15.816404Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'e'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable = 'Test String'\n", "my_str_variable[1]" @@ -422,42 +581,75 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.031105Z", "start_time": "2020-02-03T15:44:16.025334Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'S'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[5]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.223295Z", "start_time": "2020-02-03T15:44:16.218071Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'g'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[-1]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.412098Z", "start_time": "2020-02-03T15:44:16.408059Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'i'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[-3]" ] @@ -474,70 +666,125 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.770139Z", "start_time": "2020-02-03T15:44:16.764956Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'es'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[1:3]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.957348Z", "start_time": "2020-02-03T15:44:16.951604Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Stri'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[5:9]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.157518Z", "start_time": "2020-02-03T15:44:17.152361Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Strin'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[-6:-1]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.357536Z", "start_time": "2020-02-03T15:44:17.352390Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'est String'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[1:]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.655484Z", "start_time": "2020-02-03T15:44:17.650201Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Test Strin'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[:-1]" ] @@ -556,28 +803,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:20.584891Z", "start_time": "2020-02-03T15:44:20.579449Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Ts tig'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[::2]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:21.319490Z", "start_time": "2020-02-03T15:44:21.313733Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'sSi'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable[2:10:3]" ] @@ -596,14 +865,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:23.717933Z", "start_time": "2020-02-03T15:44:23.712350Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\n", + "e\n", + "l\n", + "l\n", + "o\n" + ] + } + ], "source": [ "my_str, idx = 'hello', 0\n", "while idx < 5:\n", @@ -621,14 +902,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:41.876818Z", "start_time": "2020-02-03T15:44:41.871637Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str = 'hello'\n", "\n", @@ -662,7 +954,12 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "my_str,ind= 'hello', 0\n", + "while idx < len(my_str):\n", + " print(my_str[idx])\n", + " idx += 1\n" + ] }, { "attachments": {}, @@ -682,10 +979,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "H\n", + "e\n", + "l\n", + "l\n", + "o\n" + ] + } + ], + "source": [ + "my_str = 'Hello'\n", + "for idx in range(len(my_str)):\n", + " print(my_str[idx])" + ] }, { "attachments": {}, @@ -741,6 +1054,31 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Sean\n", + "Hello Sean\n", + "Hello Sean\n" + ] + } + ], + "source": [ + "my_name = 'Sean'\n", + "\n", + "print('Hello %s' % my_name)\n", + "\n", + "print('Hello {}'.format(my_name))\n", + "\n", + "print(f'Hello {my_name}')" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -757,6 +1095,13 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -784,12 +1129,130 @@ " * What happens if you split by a comma and a space (`', '`)?" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Answer 1. when the string itself contains quots. " + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "They told me not to do this, but I didn't listen.\n" + ] + } + ], + "source": [ + "my_str_variable = \"They told me not to do this, but I didn't listen.\"\n", + "print(my_str_variable)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello elham\n" + ] + } + ], + "source": [ + "a = 'elham'\n", + "b = 'Sara'\n", + "print('Hello ' +a)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Htllo, Stan'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_string = 'Hello, Sean'\n", + "my_string. replace('e' , 't')" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Hello,', 'Sean']" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_string.split()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Hello', ' Sean']" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_string.split(',')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Hello', 'Sean']" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_string.split(', ')" + ] } ], "metadata": { @@ -808,7 +1271,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb b/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb index c8babd23..9cf7d159 100644 --- a/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb @@ -71,28 +71,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.372095Z", "start_time": "2020-02-03T11:53:01.362664Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "bool" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(True)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.377605Z", "start_time": "2020-02-03T11:53:01.373799Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "bool" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(False)" ] @@ -107,84 +129,150 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.383289Z", "start_time": "2020-02-03T11:53:01.379756Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 == 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.388673Z", "start_time": "2020-02-03T11:53:01.385142Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 != 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.394825Z", "start_time": "2020-02-03T11:53:01.390376Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 < 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.400648Z", "start_time": "2020-02-03T11:53:01.396761Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 > 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.406052Z", "start_time": "2020-02-03T11:53:01.402467Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 <= 2" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.411632Z", "start_time": "2020-02-03T11:53:01.408212Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "1 >= 2" ] @@ -219,14 +307,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:03.876556Z", "start_time": "2020-02-03T11:53:01.413240Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "x = input('Please enter a number: ')\n", "print(x)" @@ -242,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:44.215172Z", @@ -250,7 +346,15 @@ }, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "x = int(input('Please enter a number: '))\n", "if x > 5:\n", @@ -268,13 +372,6 @@ "**Note**: `input()` actually interprets the input as strings, so we have to manually tell Python to treat the number we pass as an integer with `int()`." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "attachments": {}, "cell_type": "markdown", @@ -316,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T14:44:59.606574Z", @@ -324,7 +421,15 @@ }, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You entered a positive number.\n" + ] + } + ], "source": [ "x = int(input('Please enter a number: '))\n", "if x < 0:\n", @@ -353,14 +458,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T14:45:15.855255Z", "start_time": "2020-02-03T14:45:13.319331Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You entered a number bigger than 5.\n" + ] + } + ], "source": [ "x = int(input('Please enter a number: '))\n", "if x > 5:\n", @@ -387,13 +500,6 @@ "**Note**: The `else` part of the statement is actually optional. If it is not included, then we'd notice that at most one of the conditional blocks in an `if`-`else` statement will be evaluated." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "attachments": {}, "cell_type": "markdown", @@ -412,7 +518,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.522244Z", @@ -441,14 +547,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.528373Z", "start_time": "2020-02-03T11:53:08.524546Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ "x = 4\n", "if x > 10 or x < 5:\n", @@ -457,7 +571,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.536062Z", @@ -489,9 +603,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You are either too young or in the wrong country!\n" + ] + } + ], "source": [ "country = \"US\"\n", "age = 18\n", @@ -542,6 +664,141 @@ "3. Write the following condition in Python: if x isn't a positive number print x.\n", "4. Write the following condition in Python: if x is between 1 and 50 except the numbers between 25 to 30 print x." ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is smaller than 100\n" + ] + } + ], + "source": [ + "x = 14\n", + "if x< 100:\n", + " print('The number is smaller than 100')" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You entered a positive number.\n", + "The number is: 5\n" + ] + } + ], + "source": [ + "x = int(input('Please enter a number: '))\n", + "if x >= 0:\n", + " print('You entered a positive number.')\n", + "elif (x + 50) > 0:\n", + " print('By adding 50, it will be positive.')\n", + "print('The number is:', x)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a big number.\n" + ] + } + ], + "source": [ + "x = 100\n", + "if (x // 10) == 0:\n", + " print('This is a single digit number.')\n", + "elif (x // 100) == 0:\n", + " print('This is a double digit number.')\n", + "else:\n", + " print('This is a big number.')" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is between 20 and 30.\n" + ] + } + ], + "source": [ + "x = 25\n", + "if (x >= 20 or x >= 30) : \n", + " print('The number is between 20 and 30.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20\n" + ] + } + ], + "source": [ + "x = 20\n", + "if x > 10 :\n", + " print (x)\n", + "\n", + "if (x // 10) > 0:\n", + " print (x)" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [], + "source": [ + "x = 20\n", + "if not (x > 0) :\n", + " print (x)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n" + ] + } + ], + "source": [ + "if x>=1 and x<=50 and not(x>=25 and x<=30):\n", + " print(x)" + ] } ], "metadata": { @@ -560,7 +817,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.13" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb b/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb index 71dc925d..4e46b0ab 100644 --- a/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb @@ -211,9 +211,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "8\n", + "10\n" + ] + } + ], "source": [ "my_list = [5, 8, 10]\n", "for i in my_list:\n", @@ -222,9 +232,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max\n", + "Moritz\n", + "Monika\n" + ] + } + ], "source": [ "names = [\"Max\", \"Moritz\", \"Monika\"]\n", "for name in names:\n", @@ -233,9 +253,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ], "source": [ "for x in range(10):\n", " print(x)" @@ -279,14 +316,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T13:52:12.530455Z", "start_time": "2020-02-03T13:52:12.522080Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loop #: 1, x: 1 and Total: 1\n", + "Loop #: 2, x: 2 and Total: 3\n", + "Loop #: 3, x: 3 and Total: 6\n", + "Loop #: 4, x: 4 and Total: 10\n", + "Loop #: 5, skipped x: 5 and Total: 10\n", + "Loop #: 6, x: 6 and Total: 16\n", + "Loop #: 7, x: 7 and Total: 23\n", + "Loop #: 8, x: 8 and Total: 31\n", + "Loop #: 9, final x: 9 and final total: 31\n" + ] + } + ], "source": [ "total, x = 0, 1\n", "loop_counter = 1\n", @@ -341,14 +394,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T13:52:24.516622Z", "start_time": "2020-02-03T13:52:24.510260Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loop #: 1, x: 1 and Total: 1\n", + "Loop #: 2, x: 2 and Total: 3\n", + "Loop #: 3, x: 3 and Total: 6\n", + "Loop #: 4, x: 4 and Total: 10\n", + "Loop #: 5, x: 5 and Total: 15\n", + "Loop #: 6, x: 6 and Total: 21\n", + "Loop #: 7, x: 7 and Total: 28\n", + "At Loop # 8 the while-loop was terminated.\n", + "The sum exceeded the max value of 25. Your Total is set to 28.\n" + ] + } + ], "source": [ "total, x = 0, 1\n", "loop_counter = 1\n", @@ -422,7 +491,17 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n" + ] + } + ], "source": [ "for i in range(0, 10):\n", " if i == 3:\n", @@ -434,7 +513,23 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ], "source": [ "for i in range(0, 10):\n", " if i == 3:\n", @@ -443,7 +538,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -451,7 +545,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -474,24 +567,80 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2020-02-03T13:52:54.890048Z", - "start_time": "2020-02-03T13:52:43.542233Z" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n" + ] } - }, - "outputs": [], + ], "source": [ - "total, x = 0, 1\n", - "while x >= 0:\n", - " total += x\n", - " x += 1\n", - "print(total)" + "i = 1\n", + "my_sum = 0\n", + "while i != 10:\n", + " my_sum += i\n", + " i += 1\n", + "print(my_sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "44\n" + ] + } + ], + "source": [ + "i = 2\n", + "my_sum = 0\n", + "while i != 10:\n", + " my_sum += i\n", + " i += 1\n", + "print(my_sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "48\n" + ] + } + ], + "source": [ + "i = 3\n", + "my_sum = 0\n", + "while (i <= 14):\n", + " if i%2 != 0:\n", + " my_sum += i\n", + " i += 2\n", + "print(my_sum)" ] }, { "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Check your understanding" + ] + }, + { "cell_type": "markdown", "metadata": {}, "source": [ @@ -504,6 +653,89 @@ "4. You have a list with all continents ( continents = [\"Africa\", \"Antarctica\", \"Asia\", \"Australia and Oceania\", \"Europe\", \"North America\", \"South America\"] ). Can you print only the continents from the southern hemisphere?" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n" + ] + } + ], + "source": [ + "sum = 0\n", + "for i in range(10):\n", + " sum += i\n", + "print(sum)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "44\n" + ] + } + ], + "source": [ + "sum = 0\n", + "for i in range(2,10) :\n", + " sum += i\n", + "print(sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "48\n" + ] + } + ], + "source": [ + "sum = 0\n", + "for i in range(3,14,2):\n", + " sum += i\n", + "print(sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Antarctica\n", + "Asia\n", + "North America\n" + ] + } + ], + "source": [ + "continents = [\"Africa\", \"Antarctica\", \"Asia\", \"Australia and Oceania\", \"Europe\", \"North America\", \"South America\"]\n", + "\n", + "for i in continents:\n", + " if (i=='Antarctica') or (i=='Europa') or (i=='North America') or (i=='Asia'):\n", + " print(i)\n" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -519,6 +751,13 @@ " " ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -577,7 +816,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "metadata": { "interpreter": { diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb index da8a262f..af4d057b 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -64,16 +64,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 'hello', 3, 'goodbye']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_first_lst" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -82,9 +93,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['h', 'e', 'l', 'l', 'o']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_second_lst" ] @@ -99,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -108,9 +130,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2, 3], ['str1', 'str2', 'str3'], [1, 'mixed', 3]]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_lst_of_lsts" ] @@ -157,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -166,9 +199,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# indexing\n", "my_lst[1]" @@ -176,9 +220,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['hello']" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# slicing\n", "my_lst[2:3]" @@ -195,18 +250,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 'hello', 'goodbye']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_lst[:]" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'goodbye'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_lst[-1]" ] @@ -221,7 +298,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -230,9 +307,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 7, 10]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# grab every third element of whole list\n", "my_lst[::3]" @@ -240,9 +328,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# grab every third element ending with element #4\n", "my_lst[:4:3]" @@ -266,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -275,9 +374,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], "source": [ "for num in my_lst:\n", " print(num)" @@ -297,9 +408,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1\n", + "1 2\n", + "2 3\n", + "3 4\n", + "4 5\n" + ] + } + ], "source": [ "for idx, num in enumerate(my_lst):\n", " print(idx, num)" @@ -354,6 +477,44 @@ " " ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 1, 2, 3, 4]\n", + "[3, 45, 78, 6, 0]\n", + "[1.2, 4.3, 5.9, 6.4, 8.34]\n", + "[1.2, 3, 't4']\n", + "[[0, 1, 2, 3, 4], [1.2, 3, 't4'], ['a', 'f', 't']]\n", + "[(0, 1.2, 'H'), (1, 3, 'e'), (2, 't4', 'l')]\n" + ] + } + ], + "source": [ + "mylist1 = list(range(5))\n", + "print(mylist1)\n", + "\n", + "mylist2 = [3, 45, 78, 6, 0]\n", + "print(mylist2)\n", + "\n", + "mylist3 = [1.2, 4.3, 5.9, 6.4, 8.34]\n", + "print(mylist3)\n", + "\n", + "mylist3 = [1.2, 3, 't4']\n", + "print(mylist3)\n", + "\n", + "mylist_of_list1= [mylist1, mylist3, ['a', 'f', 't']]\n", + "print(mylist_of_list1)\n", + "\n", + "mylist_of_list2= list(zip(mylist1, mylist3, list('Hello')))\n", + "print(mylist_of_list2)\n" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -373,6 +534,62 @@ "9. How many items are now in your list? (you can check if your right with `len(my_list)`)" ] }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10]\n", + "[2, 4, 6, 8, 10, 12]\n", + "[12, 10, 8, 6, 4, 2]\n", + "The number of value 12 in list is: 1\n", + "The number of value 12 in list is: 2\n", + "[2, 4, 6, 8, 10, 12, 12]\n", + "[2, 4, 6, 8, 10, 12]\n" + ] + }, + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "even_lst = []\n", + "for i in range(1,11):\n", + " if i%2 == 0 :\n", + " even_lst.append(i) \n", + "print(even_lst)\n", + "\n", + "even_lst.append(12)\n", + "print(even_lst)\n", + "\n", + "even_lst.reverse()\n", + "print(even_lst)\n", + "\n", + "print('The number of value 12 in list is:' , even_lst.count(12))\n", + "\n", + "even_lst.append(12)\n", + "print('The number of value 12 in list is:' , even_lst.count(12))\n", + "\n", + "even_lst.sort()\n", + "print(even_lst)\n", + "\n", + "even_lst.pop()\n", + "print(even_lst)\n", + "\n", + "len(even_lst)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -387,6 +604,31 @@ "3. How would I use interval indexing to grab 7 and 15 from the list?" ] }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n", + "22\n", + "12\n", + "[7, 15]\n" + ] + } + ], + "source": [ + "pre_lst = [3, 7, 12, 15, 22]\n", + "\n", + "print(pre_lst[1])\n", + "print(pre_lst[4])\n", + "print(pre_lst[-3])\n", + "print(pre_lst[1:4:2])" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -404,6 +646,58 @@ "4. Now modify the `for` loop so that we print out the index of the elements along with the elements themselves." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n", + "8\n", + "10\n", + "[0, 2, 4, 6, 8, 10]\n", + "1\n", + "3\n", + "5\n", + "7\n", + "9\n", + "[1, 3, 5, 7, 9]\n", + "0 0\n", + "1 2\n", + "2 4\n", + "3 6\n", + "4 8\n", + "5 10\n" + ] + } + ], + "source": [ + "evens =[]\n", + "my_list = range(0,11)\n", + "for i in my_list:\n", + " if i%2 == 0:\n", + " print(i)\n", + " evens.append(i)\n", + "print(evens)\n", + "\n", + "odds =[]\n", + "my_list = range(0,11)\n", + "for i in my_list:\n", + " if i%2 == 1:\n", + " print(i)\n", + " odds.append(i)\n", + "print(odds)\n", + "3\n", + "for indx, value in enumerate(evens):\n", + " print(indx, value)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -442,7 +736,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ @@ -456,8 +750,67 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "'Customer 3: Gina is 85 years oldand has bought Photo Album'" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "f\"Customer 3: {customers[2][0]} is {customers[2][1]} years oldand has bought {customers[2][2]}\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Paul is 33 yearsn old and has bought Macbook Pro .\n", + "Anna is 12 yearsn old and has bought Looping Louie .\n", + "Gina is 85 yearsn old and has bought Photo Album .\n", + "Kim is 59 yearsn old and has bought Plants .\n" + ] + } + ], + "source": [ + "for name_cust, age_cust, prod_cust in customers:\n", + " print(name_cust, 'is',age_cust,'yearsn old and has bought', prod_cust,'.')\n", + " f\"Customer {name_cust} is {age_cust} years old and has bought {prod_cust}.\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer 0: Paul is 33 years old and has bought Macbook Pro.\n", + "Customer 1: Anna is 12 years old and has bought Looping Louie.\n", + "Customer 2: Gina is 85 years old and has bought Photo Album.\n", + "Customer 3: Kim is 59 years old and has bought Plants.\n" + ] + } + ], + "source": [ + "\n", + "for i, cust in enumerate(customers):\n", + " name_cust, age_cust, prod_cust = cust\n", + " print(f\"Customer {i}: {name_cust} is {age_cust} years old and has bought {prod_cust}.\")\n" + ] } ], "metadata": { @@ -476,7 +829,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "vscode": { "interpreter": { diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb index df2f69b1..be70e2f0 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -60,9 +60,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# we create identical sets:\n", "my_set == my_other_set" @@ -89,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -98,18 +109,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 5, 6, 7}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_set.union(my_other_set)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_set.add(4)\n", "my_set" @@ -117,9 +150,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4, 5, 6, 7}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_set.update(my_other_set)\n", "my_set" @@ -127,9 +171,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4, 6, 7}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_set.remove(5)\n", "my_set" @@ -137,9 +192,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{6, 7}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_set.intersection(my_other_set)" ] @@ -176,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -185,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -194,18 +260,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "790 µs ± 2.06 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n" + ] + } + ], "source": [ "timeit 100000 in my_list" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "26.2 ns ± 0.185 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n" + ] + } + ], "source": [ "timeit 100000 in my_set" ] @@ -239,6 +321,33 @@ "5. In one line of code, add all the elements of `second_set` to `first_set`." ] }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9, 'Hello'}" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_set = set(range(1,11))\n", + "second_set = set(range(5,16))\n", + "first_set.add(11)\n", + "second_set.add('Hello')\n", + "\n", + "first_set.intersection(second_set)\n", + "\n", + "first_set.union(second_set)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -253,15 +362,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'chicken wings', 'soda'}\n", + "True\n" + ] + } + ], + "source": [ + "first_list = ['hello', 'there', 'things', 'stuff', 'other', 'soda', 'chicken wings', 'things', 'soda']\n", + "second_list = ['turkey sandwich', 'guacamole', 'chicken wings', 'OJ', 'soda']\n", + "uniq_elm = set(first_list)\n", + "inter_elm = set(first_list).intersection(set(second_list))\n", + "print(inter_elm)\n", + "\n", + "uni_elm = set(first_list).union(set(second_list))\n", + "\n", + "bool_pizza = uni_elm.isdisjoint('pizza')\n", + "print(bool_pizza)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.4 ('.venv': venv)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -275,12 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" - }, - "vscode": { - "interpreter": { - "hash": "856105b4be0f061912d9e3bd57601f265232cc0f0021e629e6ca084c3e4ca463" - } + "version": "3.9.6" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb index 821ac13a..1991cd1f 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb @@ -42,9 +42,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "l = list(range(10))\n", "l" @@ -52,9 +63,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 0, 5, 6, 7, 8, 9]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "l[4] = 0\n", "l" @@ -62,9 +84,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 0, 5, 6, 7, 8, 9, 1]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "l.append(1)\n", "l" @@ -81,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -91,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -130,9 +163,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 2)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_first_tuple = tuple([1, 2])\n", "my_first_tuple" @@ -140,9 +184,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 2)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_other_tuple = (1, 2)\n", "my_other_tuple" @@ -150,9 +205,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 2)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_third_tuple = 1, 2\n", "my_third_tuple" @@ -167,9 +233,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "evens = []\n", "for element in range(1, 21):\n", @@ -189,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -198,27 +275,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(t[0])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(t[1])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(t[2])" ] @@ -227,7 +337,18 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(t[3])" ] @@ -243,7 +364,18 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 'bird', [1, 2, 3], (1, 2))" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "t[2].append(3)\n", "t" @@ -285,6 +417,45 @@ "6. Make sure that you tried out the code from the above examples. Did those operations return anything? Why or why not?\n" ] }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 200, 6, 7, 8, 9, 10]\n", + "[1, 2, 3, 4, 200, 6, 7, 8, 9, 10, 9]\n", + "[1, 2, 3, 4, 6, 7, 8, 9, 9, 10, 200]\n", + "['Hello', 1, 2, 3, 4, 6, 7, 8, 9, 9, 10, 200]\n", + "[200, 10, 9, 9, 8, 7, 6, 4, 3, 2, 1, 'Hello']\n" + ] + } + ], + "source": [ + "my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", + "my_list[4] = 200\n", + "print(my_list)\n", + "my_list.append(9)\n", + "print(my_list)\n", + "my_list.sort()\n", + "print(my_list)\n", + "my_list.insert(0, 'Hello')\n", + "print(my_list)\n", + "my_list.reverse()\n", + "print(my_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5 - Because List are Mutable. \n", + "6 - Because the changes are applied directly to the existing list instead of creating new one. these oprerations returns None. " + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -300,6 +471,68 @@ " 2. Add the word `\"hello\"` to the list in the tuple as the first element in the list." ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "Hello\n" + ] + } + ], + "source": [ + "my_tuple = (1, 'Hello')\n", + "print(my_tuple[0])\n", + "print(my_tuple[1])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2- No, because tuples are not mutable. " + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "other_tuple = ('other', [])\n", + "other_tuple[1].append('there')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1- Bcause lists in tuples are mutable. " + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('other', ['Hello', 'there'])\n" + ] + } + ], + "source": [ + "other_tuple[1].insert(0, 'Hello')\n", + "print(other_tuple)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -324,7 +557,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" + "version": "3.9.6" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb index 5d8dfb4b..f66e33c1 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb @@ -33,9 +33,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('Georgia', 'Atlanta'), ('Colorado', 'Denver'), ('Indiana', 'Indianapolis')]" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "states_caps = [('Georgia', 'Atlanta'), ('Colorado', 'Denver'), ('Indiana', 'Indianapolis')]\n", "states_caps" @@ -51,9 +62,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Indianapolis'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "search_state = 'Indiana'\n", "capital = 'State not found'\n", @@ -76,9 +98,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Georgia': 'Atlanta', 'Colorado': 'Denver', 'Indiana': 'Indianapolis'}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "states_caps_dict = {'Georgia': 'Atlanta', 'Colorado': 'Denver', 'Indiana': 'Indianapolis'}\n", "states_caps_dict" @@ -96,18 +129,41 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Indianapolis'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "states_caps_dict['Indiana']" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'Washington'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mstates_caps_dict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mWashington\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mKeyError\u001b[0m: 'Washington'" + ] + } + ], "source": [ "states_caps_dict['Washington']" ] @@ -124,9 +180,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'State not found'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "states_caps_dict.get('Washington', 'State not found')" ] @@ -159,9 +226,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_dict = {'thing': 1, 'other': 2}\n", "my_dict['thing']" @@ -169,9 +247,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'thing': 3, 'other': 2}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_dict['thing'] = 3\n", "my_dict" @@ -179,14 +268,32 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'thing': 3, 'other': 2, 'thingy': 4}" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_dict['thingy'] = 4\n", "my_dict" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -229,9 +336,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'list'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[13], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m my_bad_key \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mkey\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m----> 2\u001b[0m my_dict \u001b[38;5;241m=\u001b[39m {my_bad_key: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThis wont work\u001b[39m\u001b[38;5;124m'\u001b[39m}\n", + "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'" + ] + } + ], "source": [ "my_bad_key = ['key']\n", "my_dict = {my_bad_key: 'This wont work'}" @@ -268,9 +387,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n", + "8\n" + ] + } + ], "source": [ "for element in range(10):\n", " if element % 2 == 0:\n", @@ -287,9 +418,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Georgia': 'Atlanta', 'Colorado': 'Denver', 'Indiana': 'Indianapolis'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "states_caps_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Georgia\n", + "Colorado\n", + "Indiana\n" + ] + } + ], "source": [ "for thing in states_caps_dict:\n", " print(thing)" @@ -307,9 +468,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Atlanta\n", + "Denver\n", + "Indianapolis\n" + ] + } + ], "source": [ "for value in states_caps_dict.values():\n", " print(value)" @@ -327,9 +498,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Georgia Atlanta\n", + "Colorado Denver\n", + "Indiana Indianapolis\n" + ] + } + ], "source": [ "for state, capital in states_caps_dict.items():\n", " print(state, capital)" @@ -345,12 +526,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Georgia', 'Atlanta')\n", + "('Colorado', 'Denver')\n", + "('Indiana', 'Indianapolis')\n" + ] + }, + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "for thing in states_caps_dict.items():\n", - " print(thing)" + " print(thing)\n", + "\n", + "len(thing)" ] }, { @@ -386,6 +589,45 @@ "3. What if you don't know whether or not `'Outback Steakhouse'` is in the `restaurant_types` dictionary - how would you go about trying to get it's restaurant type and make sure that you won't get an error?" ] }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fast Food\n" + ] + } + ], + "source": [ + "resturant_types = {'Red Lobster': 'Seafood', 'Burger King': 'Fast Food' , 'Safeway':'Grocery Store'}\n", + "x = resturant_types['Burger King']\n", + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Restaurnt not found'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "resturant_types.get('Outback Steakhouse', 'Restaurnt not found')" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -401,6 +643,31 @@ " 3. Google it." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'Burger King'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[37], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m resturant_types [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOutback Steakhouse\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDelicious!\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 2\u001b[0m resturant_types [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSafeway\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGrocery!\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m----> 3\u001b[0m \u001b[43mresturant_types\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mBurger King\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m resturant_types\n", + "\u001b[0;31mKeyError\u001b[0m: 'Burger King'" + ] + } + ], + "source": [ + "\n", + "resturant_types ['Outback Steakhouse'] = 'Delicious!'\n", + "resturant_types ['Safeway'] = 'Grocery!'\n", + "resturant_types.pop('Burger King')\n", + "resturant_types" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -413,6 +680,47 @@ "3. Write a for loop that prints the all the restaurants that are of type `'Seafood'`." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Red Lobster\n", + "Safeway\n", + "Outback Steakhouse\n" + ] + } + ], + "source": [ + "for all_keys in resturant_types.keys():\n", + " print(all_keys)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Red Lobster\n", + "Outback Steakhouse\n" + ] + } + ], + "source": [ + "for all_key in resturant_types.keys():\n", + " if len(all_key) > 10 : \n", + " print(all_key)\n" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -439,6 +747,48 @@ "2. Check if a certain key (1 and 7) already exist in your dictionary. If not please return \"Key not found\"." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dic1={1:10, 2:20}\n", + "dic2={3:30, 4:40}\n", + "dic3={5:50, 6:60}\n", + "list_dict = [dic1, dic2, dic3]\n", + "dic_concat ={}\n", + "for i in list_dict:\n", + " for thing in i.items():\n", + " dic_concat.update([thing])\n", + "print(dic_concat)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n" + ] + } + ], + "source": [ + "dic1={1:10, 2:20}\n", + "dic2={3:30, 4:40}\n", + "dic3={5:50, 6:60}\n", + "list_dict = [dic1, dic2, dic3]\n", + "dic_concat ={}\n", + "for i in list_dict:\n", + " for thing in i.items():\n", + " dic_concat.update([thing])\n", + "print(dic_concat)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -447,6 +797,26 @@ "3. Write a Python script to generate and print a dictionary that contains a number (between 1 and 10) in the form (x, x*x). (hint: use a for loop)" ] }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}\n" + ] + } + ], + "source": [ + "dic_power={}\n", + "for i in range(1,11):\n", + " dic_power[i] = i*i\n", + "print(dic_power)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -455,6 +825,26 @@ "4. Write a Python program to sum all the items in dictionary." ] }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "385" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(dic_power.values())" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -467,8 +857,21 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Sara': 24, 'Alex': 65, 'Amir': 45, 'Mary': 37, 'Mona': 10}\n" + ] + } + ], + "source": [ + "my_list_name = ['Sara', 'Alex', 'Amir', 'Mary', 'Mona']\n", + "my_list_age = [24, 65, 45, 37, 10]\n", + "\n", + "dict_zip = dict(zip(my_list_name,my_list_age))" + ] } ], "metadata": { @@ -487,7 +890,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb index d483b931..cac573b0 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb @@ -56,14 +56,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.671661Z", "start_time": "2020-07-20T10:02:41.651576Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 25, 81, 1089]\n" + ] + } + ], "source": [ "my_list = [1, 5, 9, 33]\n", "my_squares = []\n", @@ -98,14 +106,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.686882Z", "start_time": "2020-07-20T10:02:41.678813Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 25, 81, 1089]\n" + ] + } + ], "source": [ "my_squares2 = [num ** 2 for num in my_list]\n", "print(my_squares2)" @@ -169,14 +185,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.709097Z", "start_time": "2020-07-20T10:02:41.691082Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n" + ] + } + ], "source": [ "# Standard way. \n", "squares_dict = {}\n", @@ -187,14 +211,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.734676Z", "start_time": "2020-07-20T10:02:41.719505Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n" + ] + } + ], "source": [ "# Dictionary Comprehension way. \n", "squares_dict2 = {num: num ** 2 for num in range(1, 6)}\n", @@ -213,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.750956Z", @@ -228,14 +260,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.769524Z", "start_time": "2020-07-20T10:02:41.760226Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'cow': 8, 'chicken': 7, 'horse': 5, 'moose': 4}\n" + ] + } + ], "source": [ "animals_dict = {animal: randint(1, 10) for animal in animals_list}\n", "print(animals_dict)" @@ -259,14 +299,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.778626Z", "start_time": "2020-07-20T10:02:41.772327Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0, 2, 4, 6, 8)\n" + ] + } + ], "source": [ "my_tuple = tuple(num for num in range(10) if num % 2 == 0)\n", "print(my_tuple)" @@ -313,6 +361,95 @@ " " ] }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 3, 5, 7, 9]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "odds = []\n", + "for num in range(10):\n", + " if num % 2 != 0: \n", + " odds.append(num)\n", + "odds\n", + "\n", + "odds = [num for num in range(1,10) if num % 2 != 0]\n", + "odds" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1: 1, 2: 8, 3: 27, 4: 64, 5: 125}" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cubes = {}\n", + "for num in range(1,6):\n", + " cubes[num] = num ** 3\n", + "cubes" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1: 1, 2: 8, 3: 27, 4: 64, 5: 125}" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cubes = {num : num**3 for num in range(1,6)}\n", + "cubes" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (3743952370.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[32], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m cubes = dict(num : num**3 for num in range(1,6))\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "cubes = dict(num : num**3 for num in range(1,6))" + ] + }, { "cell_type": "code", "execution_count": null, @@ -337,7 +474,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Functions/1_Introduction_to_Functions.ipynb b/04_python_practice/01_Python_Basics/Functions/1_Introduction_to_Functions.ipynb index 1839e655..97f5abdd 100644 --- a/04_python_practice/01_Python_Basics/Functions/1_Introduction_to_Functions.ipynb +++ b/04_python_practice/01_Python_Basics/Functions/1_Introduction_to_Functions.ipynb @@ -107,14 +107,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:11:38.576106Z", "start_time": "2020-07-20T09:11:38.562307Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 2, 4, 6, 8]\n" + ] + } + ], "source": [ "evens = []\n", "for element in range(10):\n", @@ -147,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:15:46.399540Z", @@ -175,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:16:02.946707Z", @@ -199,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:21:28.680629Z", @@ -226,14 +234,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:21:31.717342Z", "start_time": "2020-07-20T09:21:31.698946Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens()" ] @@ -248,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:22:48.392759Z", @@ -267,14 +286,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:22:49.942329Z", "start_time": "2020-07-20T09:22:49.932672Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens()" ] @@ -312,10 +342,119 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_evens(): \n", + " evens = []\n", + " for element in range(10): \n", + " if element % 2 == 0: \n", + " evens.append(element)\n", + " return evens\n", + "\n", + "get_evens()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5- No, the function has no input parameter.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_evens(): \n", + " evens = []\n", + " for element in range(19): \n", + " if element % 2 == 0: \n", + " evens.append(element)\n", + " return evens\n", + "get_evens()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9, 12, 15, 18]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def multip(): \n", + " mul_three = [mul for mul in range(19) if mul%3 == 0]\n", + " return mul_three\n", + "multip()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5- No, the function has no input parameter.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def multip(): \n", + " mul_three = []\n", + " for element in range(19): \n", + " if element % 3 == 0: \n", + " mul_three.append(element)\n", + " return mul_three\n", + "multip()" + ] } ], "metadata": { @@ -334,7 +473,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Functions/2_Function_Definitions.ipynb b/04_python_practice/01_Python_Basics/Functions/2_Function_Definitions.ipynb index 3a566348..c181aa21 100644 --- a/04_python_practice/01_Python_Basics/Functions/2_Function_Definitions.ipynb +++ b/04_python_practice/01_Python_Basics/Functions/2_Function_Definitions.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:26:49.271964Z", @@ -62,53 +62,79 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:27:26.624940Z", "start_time": "2020-07-20T09:27:26.605458Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:27:27.548548Z", "start_time": "2020-07-20T09:27:27.541263Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(14)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:27:28.455924Z", "start_time": "2020-07-20T09:27:28.445454Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(20)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "attachments": {}, "cell_type": "markdown", @@ -119,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:28:35.407153Z", @@ -138,56 +164,100 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:28:36.104646Z", "start_time": "2020-07-20T09:28:36.095517Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:28:36.873361Z", "start_time": "2020-07-20T09:28:36.863387Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:28:37.600905Z", "start_time": "2020-07-20T09:28:37.592055Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(14)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:28:39.837956Z", "start_time": "2020-07-20T09:28:39.826578Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_evens(20)" ] @@ -210,7 +280,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:31.208255Z", @@ -229,84 +299,150 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:31.906113Z", "start_time": "2020-07-20T09:30:31.896764Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:32.524560Z", "start_time": "2020-07-20T09:30:32.515367Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:33.057469Z", "start_time": "2020-07-20T09:30:33.048503Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(5, 2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:35.546057Z", "start_time": "2020-07-20T09:30:35.536691Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(10, 2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:36.130405Z", "start_time": "2020-07-20T09:30:36.120706Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(10, 3)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:30:37.929394Z", "start_time": "2020-07-20T09:30:37.920488Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(100, 10)" ] @@ -329,7 +465,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:31:41.488324Z", @@ -348,14 +484,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:31:43.459870Z", "start_time": "2020-07-20T09:31:43.448414Z" } }, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "non-default argument follows default argument (3489222303.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[25], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m def get_multiples(n=5, divisor):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m non-default argument follows default argument\n" + ] + } + ], "source": [ "def get_multiples(n=5, divisor): \n", " multiples_lst = []\n", @@ -399,6 +544,37 @@ "2. Call the function with a couple of different arguments. Before you call it, though, write down what you expect it to output. Do the function calls output what you expect? Why or why not?" ] }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_evens(n=6):\n", + " evens = list(num for num in range(n) if num %2 == 0)\n", + " return evens\n", + "\n", + "get_evens(8)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1- yes, because the function has input parameter. " + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -411,6 +587,56 @@ "3. Leaving the function with a default value of `20`, call it with arguments of `5` and `10`. What do you expect the output to be? Run it, and either verify your results or figure out why the output differed from what you expected. " ] }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_evens(n=10):\n", + " evens = list(num for num in range(n) if num %2 == 0)\n", + " return evens\n", + "\n", + "get_evens()\n", + "get_evens(20)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 6, 8]" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_evens(n=20):\n", + " evens = list(num for num in range(n) if num %2 == 0)\n", + " return evens\n", + "\n", + "get_evens(5)\n", + "get_evens(10)" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -422,8 +648,45 @@ "2. Now, call `get_multiples(100, 10)`. Again, note what you expect this call will output before calling it. Is the output the same as in `1`. Why or why not?" ] }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def get_multiples(n=100, divisor=20):\n", + " multi_num = list(mul for mul in range(n) if mul % divisor == 0)\n", + " return multi_num\n", + "\n", + "get_multiples()\n", + "get_multiples(100,10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2- Because the input parameter has changed. " + ] + }, { "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { "cell_type": "markdown", "metadata": {}, "source": [ @@ -461,12 +724,90 @@ "2. Verify your answers by typing these into cells, or figure out why you don't see the results you expected. " ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1- functions 2, 3, 5, 6 are valid. " + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "non-default argument follows default argument (3695065915.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[49], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m def my_func1(var1='Hello', var2):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m non-default argument follows default argument\n" + ] + } + ], + "source": [ + "def my_func1(var1='Hello', var2): \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def my_func2(var1, var2='Hello'): \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "def my_func3(var1, var2=35): \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "non-default argument follows default argument (2217873552.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[53], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m def my_func4(var1=35, var2):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m non-default argument follows default argument\n" + ] + } + ], + "source": [ + "def my_func4(var1=35, var2): \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "def my_func5(var1=35, var2='Hello'): \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "def my_func6(var1, var2): \n", + " pass" + ] } ], "metadata": { diff --git a/04_python_practice/01_Python_Basics/Functions/3_Calling_Functions.ipynb b/04_python_practice/01_Python_Basics/Functions/3_Calling_Functions.ipynb index 242f9598..7b812d14 100644 --- a/04_python_practice/01_Python_Basics/Functions/3_Calling_Functions.ipynb +++ b/04_python_practice/01_Python_Basics/Functions/3_Calling_Functions.ipynb @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:54:35.730820Z", @@ -67,56 +67,98 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:54:35.755520Z", "start_time": "2020-07-20T09:54:35.733785Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(5, 2) # All arguments passed by position." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:54:35.774128Z", "start_time": "2020-07-20T09:54:35.760441Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(n=5, divisor=2) # All arguments passed by keyword." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:54:35.792238Z", "start_time": "2020-07-20T09:54:35.780602Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "get_multiples(10, divisor=3) # Okay mix of positional and keyword arguments." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T09:54:35.809623Z", "start_time": "2020-07-20T09:54:35.795527Z" } }, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "positional argument follows keyword argument (3694115901.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[7], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m get_multiples(n=10, 3) # Not okay mix of positional and keyword arguments.\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n" + ] + } + ], "source": [ "get_multiples(n=10, 3) # Not okay mix of positional and keyword arguments." ] @@ -166,6 +208,132 @@ " \n", "3. Verify your answers by typing these into cells, or figure out why you don't see the results you expected. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1.1- passes argument by postion\n", + "1.2- passses argument by keywords\n", + "\n", + "2. function calls 1, 3, 4, 6 are valid. " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 13]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_multiples(26, 13)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "positional argument follows keyword argument (3994683612.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[10], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m get_multiples(n=26, 13)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n" + ] + } + ], + "source": [ + "get_multiples(n=26, 13)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 13]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_multiples(26, divisor=13)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 13]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_multiples(n=26, divisor=13)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "positional argument follows keyword argument (718035730.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[13], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m get_multiples(n=48, 8)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n" + ] + } + ], + "source": [ + " get_multiples(n=48, 8)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 10, 20, 30, 40]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_multiples(50, divisor=10)" + ] } ], "metadata": { @@ -184,7 +352,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Functions/4_Functions_Challenge.ipynb b/04_python_practice/01_Python_Basics/Functions/4_Functions_Challenge.ipynb index 50179976..a81041b7 100644 --- a/04_python_practice/01_Python_Basics/Functions/4_Functions_Challenge.ipynb +++ b/04_python_practice/01_Python_Basics/Functions/4_Functions_Challenge.ipynb @@ -79,6 +79,61 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def factorial(n):\n", + " if n>1: \n", + " return factorial(n-1) * n\n", + " else: \n", + " return 1\n", + "\n", + "factorial(4)" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is not a prime number\n" + ] + } + ], + "source": [ + "def prim(n): \n", + " mul = [num for num in range(1, n+1) if n%num == 0]\n", + " if len(mul) > 2:\n", + " return False\n", + " else:\n", + " return True\n", + "\n", + "\n", + "if prim(9):\n", + " print('The number is a prime number')\n", + "else:\n", + " print('The number is not a prime number')\n", + " " + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -107,12 +162,209 @@ ] }, { - "attachments": {}, - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "### Extra Challenge\n", - "\n" + "def word_count(str_input):\n", + " return len(str_input.split())\n", + "\n", + "x = 'Today is a rainy cold witer day.'\n", + "word_count(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def word_count(str_input, delim=' '):\n", + " return len(str_input.split(delim))\n", + "\n", + "x = 'Today is a rainy cold winter day.'\n", + "y = \"As&an&example,&let's&say&my &tax &info &is\"\n", + "word_count(y, '&')" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[5, 2, 1, 5, 4, 6, 4]" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def character_counter_words(str_input, delim= ' '):\n", + " return [len(itm) for itm in str_input.split(delim)]\n", + "\n", + "character_counter_words(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number is not a prime number.\n" + ] + } + ], + "source": [ + "def prim(n): \n", + " mul = [num for num in range(1, n+1) if n%num == 0]\n", + " if len(mul) > 2:\n", + " return False\n", + " else:\n", + " return n\n", + "\n", + "\n", + "if prim(9):\n", + " print('The number is a prime number.')\n", + "else:\n", + " print('The number is not a prime number.')\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 5, 7, 11, 13, 17, 19]\n" + ] + } + ], + "source": [ + "n = 21\n", + "print( [prim(itm) for itm in range(1,n) if prim(itm)] ) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'divisor is zero.'" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def divis(lst, divi):\n", + " if divi != 0:\n", + " result = ['No' if itm % param else 'Yes' for itm in my_lst ] \n", + " return result\n", + " return ('divisor is zero.')\n", + "\n", + "\n", + "divisor =0\n", + "my_lst = [20, 76, 80, 58, 90, 34, 45, 71]\n", + "divis(my_lst, divisor)" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['sure', 'rule', 'share', 'sale']" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def word_end_char(lst_str, char):\n", + " if lst_str != []: \n", + " return [itm for itm in lst_str if itm.endswith(char)]\n", + " return 'you enterned nothing.'\n", + " \n", + "\n", + "inp_string = ['I', 'am', 'in', 'love', 'with', 'Python']\n", + "inp_string = ['sure','today', 'rule', 'share', 'sale', '']\n", + "char = 'e'\n", + "word_end_char(inp_string,char)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1]" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def substring(lst_str, word):\n", + " if lst_str != [] and word!=[]: \n", + " return [i for i, itm in enumerate(lst_str) if word in itm]\n", + " return 'your String or substing is nothing'\n", + "\n", + "\n", + "\n", + "inp_string = ['This', 'is', 'an' , 'example']\n", + "my_word = 'is'\n", + "substring(inp_string, my_word)\n" ] }, { @@ -120,6 +372,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "### Extra Challenge\n", + "\n", + "\n", "### Extra Challenge\n", "\n", "1. Let's build a calculator for figuring out how much I owe in taxes (and by calculator, I mean function). Write a function that takes in a list of tuples, where each tuple contains two values, as well as an income to compute the taxes on (so your function should accept two arguments). For the tuple list, the first value of a tuple will be an income upper bound, and the second will be a tax rate for all income up to the given income bound. You need to build a calculator that will calculate the tax for all income up to each income bound (if it goes up that high) for the given tax rate. You can assume that the list of tuples will be sorted by the income bound (e.g. the first value in the tuple), such that the lowest income bound will be first, and the highest last (see below for an example). \n", @@ -148,7 +403,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -162,7 +417,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.8" + "version": "3.9.6" }, "toc": { "base_numbering": 1, @@ -205,11 +460,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "be7dd07ef673f1c542ac4f7690ce2e5f650b2bc66c3cbf4a3f66e2fce72bd812" - } } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/requirements.txt b/04_python_practice/01_Python_Basics/requirements.txt index 947b0c8e..b85de8c5 100644 --- a/04_python_practice/01_Python_Basics/requirements.txt +++ b/04_python_practice/01_Python_Basics/requirements.txt @@ -1 +1,3 @@ jupyterlab==3.6.3 + + From 4eeb98d52ff001e963dab6b2d71363b1a5c8a4ad Mon Sep 17 00:00:00 2001 From: elham Date: Tue, 7 Oct 2025 03:23:22 +0200 Subject: [PATCH 2/3] add .venv to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e43b0f98..a9c348f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.venv/ From 2330dc98803eed33133ce673fe7412ea623026c3 Mon Sep 17 00:00:00 2001 From: elham Date: Wed, 8 Oct 2025 08:50:46 +0200 Subject: [PATCH 3/3] Add python basics excercises --- .../Basics/1_Numeric_Variable_Types.ipynb | 122 ++++----- .../01_Python_Basics/Basics/2_Strings.ipynb | 234 ++++++++++++------ .../Basics/3_If_Statement.ipynb | 75 +++--- .../01_Python_Basics/Basics/4_Loops.ipynb | 56 +++-- .../Data_Structures_in_Python/1_Lists.ipynb | 63 +++-- .../Data_Structures_in_Python/2_Sets.ipynb | 36 +-- .../3_Mutability.ipynb | 66 ++--- .../4_Dictionaries.ipynb | 48 ++-- .../5_Comprehension.ipynb | 34 +-- 9 files changed, 412 insertions(+), 322 deletions(-) diff --git a/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb b/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb index d74ae397..340b6cc5 100644 --- a/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/1_Numeric_Variable_Types.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.429214Z", @@ -60,7 +60,7 @@ "55" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.456179Z", @@ -85,7 +85,7 @@ "-2" ] }, - "execution_count": 4, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -96,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.503183Z", @@ -110,7 +110,7 @@ "121" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -121,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.554866Z", @@ -135,7 +135,7 @@ "0.375" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -146,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.565917Z", @@ -160,7 +160,7 @@ "9" ] }, - "execution_count": 8, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -180,7 +180,7 @@ "34" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -191,7 +191,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -200,7 +200,7 @@ "50" ] }, - "execution_count": 11, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -222,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -231,7 +231,7 @@ "8" ] }, - "execution_count": 12, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -251,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -260,7 +260,7 @@ "2" ] }, - "execution_count": 13, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -282,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -291,7 +291,7 @@ "2.14" ] }, - "execution_count": 14, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -302,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -311,7 +311,7 @@ "2.14" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -322,7 +322,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -331,7 +331,7 @@ "11" ] }, - "execution_count": 16, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -342,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -351,7 +351,7 @@ "44" ] }, - "execution_count": 17, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -362,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -371,7 +371,7 @@ "3.142" ] }, - "execution_count": 18, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -400,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.694614Z", @@ -415,7 +415,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.711513Z", @@ -429,7 +429,7 @@ "'Hello'" ] }, - "execution_count": 20, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -440,7 +440,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.723777Z", @@ -454,7 +454,7 @@ "4" ] }, - "execution_count": 21, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -465,7 +465,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.736043Z", @@ -479,7 +479,7 @@ "'HelloHelloHelloHelloHelloHelloHelloHello'" ] }, - "execution_count": 22, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -506,7 +506,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.753269Z", @@ -520,7 +520,7 @@ "13" ] }, - "execution_count": 23, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -579,7 +579,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.223748Z", @@ -594,7 +594,7 @@ "14" ] }, - "execution_count": 24, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -605,7 +605,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.302631Z", @@ -620,7 +620,7 @@ "32.2" ] }, - "execution_count": 25, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -631,7 +631,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.353655Z", @@ -645,7 +645,7 @@ "(5+6j)" ] }, - "execution_count": 26, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -656,7 +656,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.379983Z", @@ -670,7 +670,7 @@ "int" ] }, - "execution_count": 27, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -681,7 +681,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.396272Z", @@ -695,7 +695,7 @@ "float" ] }, - "execution_count": 28, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -706,7 +706,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-06-30T11:34:51.410079Z", @@ -720,7 +720,7 @@ "complex" ] }, - "execution_count": 29, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -796,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -840,7 +840,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -883,7 +883,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -892,7 +892,7 @@ "int" ] }, - "execution_count": 50, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -903,7 +903,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -912,7 +912,7 @@ "float" ] }, - "execution_count": 52, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -923,7 +923,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -932,7 +932,7 @@ "complex" ] }, - "execution_count": 54, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -953,7 +953,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -974,7 +974,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -992,7 +992,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -1006,7 +1006,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb b/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb index 95b9b214..2eeabb5b 100644 --- a/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/2_Strings.ipynb @@ -8,6 +8,11 @@ "# Introduction to Strings" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -16,6 +21,13 @@ "In this notebook we are going to learn about a couple of data structures that will continue to build up your power in Python." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "attachments": {}, "cell_type": "markdown", @@ -46,44 +58,77 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:14.390114Z", "start_time": "2020-02-03T15:12:14.376906Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string.'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'This is a string.'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:14.737607Z", "start_time": "2020-02-03T15:12:14.733065Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is another string, but this time with double quotation marks.'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"This is another string, but this time with double quotation marks.\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:15.047377Z", "start_time": "2020-02-03T15:12:15.036838Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"They told me not to do this, but I didn't listen.\"" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "'They told me not to do this, but I didn't listen.' " + "\"They told me not to do this, but I didn't listen.\"" ] }, { @@ -96,28 +141,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:15.488978Z", "start_time": "2020-02-03T15:12:15.484577Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"Now that I've got double quotes, I can use all the contractions!\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"Now that I've got double quotes, I can use all the contractions!\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:15.680975Z", "start_time": "2020-02-03T15:12:15.675870Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"Can't, won't, didn't, don't... all the contractions!\"" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"Can't, won't, didn't, don't... all the contractions!\"" ] @@ -132,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:16.315983Z", @@ -146,7 +213,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:16.520959Z", @@ -160,7 +227,7 @@ "'This is a string variable.'" ] }, - "execution_count": 2, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -181,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:17.160652Z", @@ -195,7 +262,7 @@ "'My first stringMy second string'" ] }, - "execution_count": 3, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -206,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:17.391947Z", @@ -220,7 +287,7 @@ "'Repeating stringRepeating stringRepeating string'" ] }, - "execution_count": 4, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -239,7 +306,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.143676Z", @@ -253,7 +320,7 @@ "'My first string My second string'" ] }, - "execution_count": 5, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -264,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.339653Z", @@ -278,7 +345,7 @@ "'Repeating string Repeating string Repeating string '" ] }, - "execution_count": 6, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -297,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.726966Z", @@ -311,7 +378,7 @@ "'Repeating string Repeating string Repeating string'" ] }, - "execution_count": 8, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -322,7 +389,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:18.916816Z", @@ -336,7 +403,7 @@ "'Repeating string Repeating string Repeating string'" ] }, - "execution_count": 9, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -357,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.338107Z", @@ -371,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.524151Z", @@ -385,7 +452,7 @@ "'This is my string to play around with.'" ] }, - "execution_count": 11, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -396,7 +463,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.719967Z", @@ -410,7 +477,7 @@ "'THIS IS MY STRING TO PLAY AROUND WITH.'" ] }, - "execution_count": 12, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -428,7 +495,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:19.959612Z", @@ -442,7 +509,7 @@ "'this is my string to play around with.'" ] }, - "execution_count": 13, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -453,7 +520,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:20.275946Z", @@ -467,7 +534,7 @@ "'this IS my flING to PLAY around WITH.'" ] }, - "execution_count": 14, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -478,7 +545,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:12:20.525214Z", @@ -492,7 +559,7 @@ "['this', 'IS', 'my', 'STRING', 'to', 'PLAY', 'around', 'WITH.']" ] }, - "execution_count": 15, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -503,9 +570,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_str_variable.strip" ] @@ -555,7 +633,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:15.822311Z", @@ -569,7 +647,7 @@ "'e'" ] }, - "execution_count": 17, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -581,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.031105Z", @@ -595,7 +673,7 @@ "'S'" ] }, - "execution_count": 18, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -606,7 +684,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.223295Z", @@ -620,7 +698,7 @@ "'g'" ] }, - "execution_count": 19, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -631,7 +709,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.412098Z", @@ -645,7 +723,7 @@ "'i'" ] }, - "execution_count": 20, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -666,7 +744,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.770139Z", @@ -680,7 +758,7 @@ "'es'" ] }, - "execution_count": 21, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -691,7 +769,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:16.957348Z", @@ -705,7 +783,7 @@ "'Stri'" ] }, - "execution_count": 22, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -716,7 +794,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.157518Z", @@ -730,7 +808,7 @@ "'Strin'" ] }, - "execution_count": 23, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -741,7 +819,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.357536Z", @@ -755,7 +833,7 @@ "'est String'" ] }, - "execution_count": 24, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -766,7 +844,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:17.655484Z", @@ -780,7 +858,7 @@ "'Test Strin'" ] }, - "execution_count": 26, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -803,7 +881,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:20.584891Z", @@ -817,7 +895,7 @@ "'Ts tig'" ] }, - "execution_count": 27, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -828,7 +906,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:21.319490Z", @@ -842,7 +920,7 @@ "'sSi'" ] }, - "execution_count": 28, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -865,7 +943,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:23.717933Z", @@ -902,7 +980,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T15:44:41.876818Z", @@ -916,7 +994,7 @@ "5" ] }, - "execution_count": 30, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -951,7 +1029,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -979,7 +1057,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -1138,7 +1216,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -1156,7 +1234,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -1175,7 +1253,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -1184,7 +1262,7 @@ "'Htllo, Stan'" ] }, - "execution_count": 45, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1196,7 +1274,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -1205,7 +1283,7 @@ "['Hello,', 'Sean']" ] }, - "execution_count": 48, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -1216,7 +1294,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1225,7 +1303,7 @@ "['Hello', ' Sean']" ] }, - "execution_count": 49, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1236,7 +1314,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -1245,7 +1323,7 @@ "['Hello', 'Sean']" ] }, - "execution_count": 51, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1257,7 +1335,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -1271,7 +1349,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb b/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb index 9cf7d159..111796a8 100644 --- a/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/3_If_Statement.ipynb @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.372095Z", @@ -85,7 +85,7 @@ "bool" ] }, - "execution_count": 17, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -96,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.377605Z", @@ -110,7 +110,7 @@ "bool" ] }, - "execution_count": 18, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -129,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.383289Z", @@ -143,7 +143,7 @@ "False" ] }, - "execution_count": 19, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -154,7 +154,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.388673Z", @@ -168,7 +168,7 @@ "True" ] }, - "execution_count": 20, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -179,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.394825Z", @@ -193,7 +193,7 @@ "True" ] }, - "execution_count": 21, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -204,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.400648Z", @@ -218,7 +218,7 @@ "False" ] }, - "execution_count": 22, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -229,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.406052Z", @@ -243,7 +243,7 @@ "True" ] }, - "execution_count": 23, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -254,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:01.411632Z", @@ -268,7 +268,7 @@ "False" ] }, - "execution_count": 24, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:03.876556Z", @@ -319,7 +319,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n" + "78\n" ] } ], @@ -338,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:44.215172Z", @@ -351,7 +351,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2\n" + "96\n" ] } ], @@ -413,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T14:44:59.606574Z", @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T14:45:15.855255Z", @@ -518,7 +518,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.522244Z", @@ -547,7 +547,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.528373Z", @@ -571,7 +571,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T11:53:08.536062Z", @@ -603,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -667,7 +667,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -686,7 +686,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -694,7 +694,7 @@ "output_type": "stream", "text": [ "You entered a positive number.\n", - "The number is: 5\n" + "The number is: 23\n" ] } ], @@ -709,7 +709,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -732,7 +732,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -751,13 +751,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "20\n", "20\n" ] } @@ -773,7 +774,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -784,14 +785,14 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "45\n" + "20\n" ] } ], @@ -803,7 +804,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -817,7 +818,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" }, "toc": { "base_numbering": 1, diff --git a/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb b/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb index 4e46b0ab..b13140ec 100644 --- a/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb +++ b/04_python_practice/01_Python_Basics/Basics/4_Loops.ipynb @@ -44,13 +44,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "ExecuteTime": { "start_time": "2020-02-03T15:12:40.415Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + } + ], "source": [ "sum_1_8 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8\n", "print(sum_1_8)" @@ -99,14 +107,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T13:50:55.348617Z", "start_time": "2020-02-03T13:50:55.343254Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + } + ], "source": [ "total, x = 0, 1\n", "while x <= 8:\n", @@ -211,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -232,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -253,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -316,7 +332,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T13:52:12.530455Z", @@ -394,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-02-03T13:52:24.516622Z", @@ -489,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -511,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -567,7 +583,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -589,7 +605,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -611,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -655,7 +671,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -675,7 +691,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -695,7 +711,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -715,7 +731,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -802,7 +818,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -816,7 +832,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" }, "metadata": { "interpreter": { diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb index af4d057b..b5e41bde 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/1_Lists.ipynb @@ -190,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -199,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -208,7 +208,7 @@ "2" ] }, - "execution_count": 12, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -220,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -229,7 +229,7 @@ "['hello']" ] }, - "execution_count": 13, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -250,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -259,7 +259,7 @@ "[1, 2, 'hello', 'goodbye']" ] }, - "execution_count": 14, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -270,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -279,7 +279,7 @@ "'goodbye'" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -298,7 +298,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -316,7 +316,7 @@ "[1, 4, 7, 10]" ] }, - "execution_count": 17, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -328,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -337,7 +337,7 @@ "[1, 4]" ] }, - "execution_count": 18, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -365,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -374,7 +374,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -408,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -479,7 +479,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -536,7 +536,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -558,7 +558,7 @@ "6" ] }, - "execution_count": 60, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -606,7 +606,7 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -648,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -736,7 +736,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -748,7 +748,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -757,7 +757,7 @@ "'Customer 3: Gina is 85 years oldand has bought Photo Album'" ] }, - "execution_count": 90, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -769,7 +769,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -791,7 +791,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -815,7 +815,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -829,12 +829,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" - }, - "vscode": { - "interpreter": { - "hash": "c413c01f8b1ea09b7068b7c496ed5efbe6a1cd8a62b0065250cf434380022023" - } + "version": "3.11.3" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb index be70e2f0..f33f84a6 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/2_Sets.ipynb @@ -150,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -159,7 +159,7 @@ "{1, 2, 3, 4, 5, 6, 7}" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -180,7 +180,7 @@ "{1, 2, 3, 4, 6, 7}" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -192,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -201,7 +201,7 @@ "{6, 7}" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -242,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -251,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -260,14 +260,14 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "790 µs ± 2.06 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n" + "765 μs ± 21.7 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -277,14 +277,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "26.2 ns ± 0.185 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n" + "20 ns ± 0.726 ns per loop (mean ± std. dev. of 7 runs, 100,000,000 loops each)\n" ] } ], @@ -323,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -332,7 +332,7 @@ "{1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9, 'Hello'}" ] }, - "execution_count": 31, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -362,14 +362,14 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'chicken wings', 'soda'}\n", + "{'soda', 'chicken wings'}\n", "True\n" ] } @@ -390,7 +390,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -404,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb index 1991cd1f..e59c1e65 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/3_Mutability.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -51,7 +51,7 @@ "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" ] }, - "execution_count": 10, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -72,7 +72,7 @@ "[0, 1, 2, 3, 0, 5, 6, 7, 8, 9]" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -84,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -93,7 +93,7 @@ "[0, 1, 2, 3, 0, 5, 6, 7, 8, 9, 1]" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -114,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -163,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -172,7 +172,7 @@ "(1, 2)" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -184,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -193,7 +193,7 @@ "(1, 2)" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -205,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -214,7 +214,7 @@ "(1, 2)" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -233,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -242,7 +242,7 @@ "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]" ] }, - "execution_count": 11, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -266,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -275,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -284,7 +284,7 @@ "int" ] }, - "execution_count": 13, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -295,7 +295,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -304,7 +304,7 @@ "str" ] }, - "execution_count": 14, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -315,7 +315,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -324,7 +324,7 @@ "list" ] }, - "execution_count": 15, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -335,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -344,7 +344,7 @@ "tuple" ] }, - "execution_count": 16, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -362,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -371,7 +371,7 @@ "(1, 'bird', [1, 2, 3], (1, 2))" ] }, - "execution_count": 17, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -419,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -473,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -500,7 +500,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -517,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -543,7 +543,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -557,7 +557,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb index f66e33c1..7289bc63 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/4_Dictionaries.ipynb @@ -149,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -157,10 +157,10 @@ "evalue": "'Washington'", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mstates_caps_dict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mWashington\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", - "\u001b[0;31mKeyError\u001b[0m: 'Washington'" + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mstates_caps_dict\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mWashington\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[31mKeyError\u001b[39m: 'Washington'" ] } ], @@ -180,7 +180,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -226,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -247,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -268,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -336,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -387,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -418,7 +418,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -438,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -468,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -498,7 +498,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -526,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -591,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -610,7 +610,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -703,7 +703,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -766,7 +766,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -799,7 +799,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -827,7 +827,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -876,7 +876,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -890,7 +890,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" } }, "nbformat": 4, diff --git a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb index cac573b0..08af3ee1 100644 --- a/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb +++ b/04_python_practice/01_Python_Basics/Data_Structures_in_Python/5_Comprehension.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.671661Z", @@ -185,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.709097Z", @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.734676Z", @@ -245,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.750956Z", @@ -260,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.769524Z", @@ -272,7 +272,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'cow': 8, 'chicken': 7, 'horse': 5, 'moose': 4}\n" + "{'cow': 9, 'chicken': 9, 'horse': 6, 'moose': 3}\n" ] } ], @@ -299,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-07-20T10:02:41.778626Z", @@ -363,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -372,7 +372,7 @@ "[1, 3, 5, 7, 9]" ] }, - "execution_count": 28, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -390,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -399,7 +399,7 @@ "{1: 1, 2: 8, 3: 27, 4: 64, 5: 125}" ] }, - "execution_count": 25, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -413,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -422,7 +422,7 @@ "{1: 1, 2: 8, 3: 27, 4: 64, 5: 125}" ] }, - "execution_count": 31, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -434,7 +434,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -442,7 +442,7 @@ "evalue": "invalid syntax (3743952370.py, line 1)", "output_type": "error", "traceback": [ - "\u001b[0;36m Cell \u001b[0;32mIn[32], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m cubes = dict(num : num**3 for num in range(1,6))\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mcubes = dict(num : num**3 for num in range(1,6))\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" ] } ], @@ -460,7 +460,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -474,7 +474,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.3" }, "toc": { "base_numbering": 1,