diff --git a/01_materials/slides/02_comments_and_errors.ipynb b/01_materials/slides/02_comments_and_errors.ipynb index 721282ef6..8f7fa2ef6 100644 --- a/01_materials/slides/02_comments_and_errors.ipynb +++ b/01_materials/slides/02_comments_and_errors.ipynb @@ -22,9 +22,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "cannot assign to literal here. Maybe you meant '==' instead of '='? (3541004665.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m12 = x\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m cannot assign to literal here. Maybe you meant '==' instead of '='?\n" + ] + } + ], "source": [ "12 = x" ] @@ -38,9 +47,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (934255472.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m25 -\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], "source": [ "25 -" ] @@ -56,9 +74,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'my_variable' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mmy_variable\u001b[49m + \u001b[32m1\u001b[39m\n", + "\u001b[31mNameError\u001b[39m: name 'my_variable' is not defined" + ] + } + ], "source": [ "my_variable + 1" ] @@ -137,7 +167,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env (3.11.14)", "language": "python", "name": "python3" }, @@ -151,7 +181,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.14" } }, "nbformat": 4, diff --git a/01_materials/slides/03_functions.ipynb b/01_materials/slides/03_functions.ipynb index dd0ba5fe4..0c2020153 100644 --- a/01_materials/slides/03_functions.ipynb +++ b/01_materials/slides/03_functions.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "345bda77", "metadata": { "colab": { @@ -65,7 +65,15 @@ "id": "345bda77", "outputId": "600f7c37-4cd3-45ee-a5a3-04137eedaeb8" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], "source": [ "print(42)" ] @@ -82,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "d4bad1e7", "metadata": { "colab": { @@ -91,7 +99,18 @@ "id": "d4bad1e7", "outputId": "0a4308b2-73e4-413f-83ad-da40c20749f7" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(42)" ] @@ -108,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "47c6ffff", "metadata": { "colab": { @@ -117,7 +136,15 @@ "id": "47c6ffff", "outputId": "fcc37f1c-563f-4416-93d1-e03dc1a2693b" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100\n" + ] + } + ], "source": [ "print(10 ** 2)" ] @@ -136,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "3cf13d07", "metadata": { "colab": { @@ -145,14 +172,25 @@ "id": "3cf13d07", "outputId": "3bbf3381-4353-4db0-8682-e0d541affc88" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "abs(-43)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "bf9825ec", "metadata": { "colab": { @@ -161,14 +199,25 @@ "id": "bf9825ec", "outputId": "27d9c8f6-426f-4595-fc36-b2bb7e67d857" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "round(2/3)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "c1bff1ca", "metadata": { "colab": { @@ -177,14 +226,25 @@ "id": "c1bff1ca", "outputId": "e3c36027-b473-440f-d30e-07765bc5ab64" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "int(3.99)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "9c79d3da", "metadata": { "colab": { @@ -193,7 +253,18 @@ "id": "9c79d3da", "outputId": "63f9f2a8-ef80-4a62-c732-cec979ea55da" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7.0" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "float(7)" ] @@ -217,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "49041e2a", "metadata": { "colab": { @@ -226,7 +297,15 @@ "id": "49041e2a", "outputId": "b247fd1b-5004-472a-f036-336f5a8e28e7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "print(type(round(2 * 1.5)))" ] @@ -243,10 +322,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "95c23628", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on built-in function round in module builtins:\n", + "\n", + "round(number, ndigits=None)\n", + " Round a number to a given precision in decimal digits.\n", + " \n", + " The return value is an integer if ndigits is omitted or None. Otherwise\n", + " the return value has the same type as the number. ndigits may be negative.\n", + "\n" + ] + } + ], "source": [ "help(round)" ] @@ -307,7 +401,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "69a1cfea", "metadata": { "id": "69a1cfea" @@ -331,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "c9ed1dff", "metadata": { "colab": { @@ -340,7 +434,16 @@ "id": "c9ed1dff", "outputId": "3ea1b703-5025-41ab-92f4-cddac7bbe136" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "212.0\n", + "12.2\n" + ] + } + ], "source": [ "print(c_to_f(100))\n", "print(c_to_f(-11))" @@ -358,7 +461,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "f27a7980", "metadata": { "colab": { @@ -367,7 +470,18 @@ "id": "f27a7980", "outputId": "53a6e7a6-8d5d-4ba5-bf0a-0562cc0b486c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "freezing_f = c_to_f(0)\n", "freezing_f" @@ -384,12 +498,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "5fb6b608", "metadata": {}, "outputs": [], "source": [ - "# Your code goes here" + "# Your code goes here\n", + "def f_to_c(degrees_f):\n", + " \"\"\" Convert degrees from Fahrenheit to Celsius \"\"\"\n", + " return ((degrees_f - 32)*(5/9))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "d47d78fa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100.0\n", + "-11.0\n" + ] + } + ], + "source": [ + "print(f_to_c(212))\n", + "print(f_to_c(12.2))" ] }, { @@ -406,7 +543,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "e8f57c4f", "metadata": { "colab": { @@ -415,7 +552,15 @@ "id": "e8f57c4f", "outputId": "2254f921-da30-4709-f668-f6afdfbcf901" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.0\n" + ] + } + ], "source": [ "def divide(dividend, divisor):\n", " return dividend / divisor\n", @@ -425,7 +570,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "81d0aa06", "metadata": { "colab": { @@ -435,7 +580,20 @@ "id": "81d0aa06", "outputId": "0b4bfb64-27f4-44a0-ccdd-543e1e1a0cb9" }, - "outputs": [], + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mZeroDivisionError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[20]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m)\u001b[49m)\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[18]\u001b[39m\u001b[32m, line 2\u001b[39m, in \u001b[36mdivide\u001b[39m\u001b[34m(dividend, divisor)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mdivide\u001b[39m(dividend, divisor):\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mdivisor\u001b[49m\n", + "\u001b[31mZeroDivisionError\u001b[39m: division by zero" + ] + } + ], "source": [ "print(divide(2, 0))" ] @@ -456,7 +614,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "2287bab3", "metadata": { "colab": { @@ -465,7 +623,16 @@ "id": "2287bab3", "outputId": "a9692e79-99cd-4911-f494-af60185a90c7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.65\n", + "0.4\n" + ] + } + ], "source": [ "def calc_sales_tax(price, tax_rate=0.13):\n", " return price * tax_rate\n", @@ -490,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "1e81e377", "metadata": { "id": "1e81e377" @@ -515,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "34b595e3", "metadata": { "colab": { @@ -524,7 +691,18 @@ "id": "34b595e3", "outputId": "2cbdadef-e05c-4d6f-b9de-39ebca33259c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "calc_total_bill(100)" ] @@ -541,7 +719,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "bede3708", "metadata": { "colab": { @@ -550,7 +728,15 @@ "id": "bede3708", "outputId": "1408e666-dc36-4504-abe6-86bfabb0e762" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "142.0\n" + ] + } + ], "source": [ "print(calc_total_bill(100, 0.22))" ] @@ -567,7 +753,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "d1d9f3d2", "metadata": { "colab": { @@ -576,7 +762,15 @@ "id": "d1d9f3d2", "outputId": "42cd36d2-717b-4729-9f87-d7b073793a37" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "135.0\n" + ] + } + ], "source": [ "print(calc_total_bill(100, tip_rate=0.22))" ] @@ -595,7 +789,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "8dc69f93", "metadata": { "colab": { @@ -604,7 +798,18 @@ "id": "8dc69f93", "outputId": "a4575900-536e-4a9d-d3cb-8da053af11d5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function c_to_f in module __main__:\n", + "\n", + "c_to_f(degrees_c)\n", + "\n" + ] + } + ], "source": [ "help(c_to_f)" ] @@ -633,7 +838,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "5c55eb30", "metadata": { "colab": { @@ -642,7 +847,19 @@ "id": "5c55eb30", "outputId": "9528ca9e-50f6-4d24-b4d8-da0f7029c4c2" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function c_to_f in module __main__:\n", + "\n", + "c_to_f(degrees_c)\n", + " Convert degrees from Celsius to Fahrenheit\n", + "\n" + ] + } + ], "source": [ "def c_to_f(degrees_c):\n", " '''Convert degrees from Celsius to Fahrenheit'''\n", @@ -683,7 +900,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "3799ebfc", "metadata": { "colab": { @@ -693,7 +910,19 @@ "id": "3799ebfc", "outputId": "ae4453b0-1607-4f16-f98b-2ef866ad0e1e" }, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'degrees_c' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[28]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdegrees_c\u001b[49m\n", + "\u001b[31mNameError\u001b[39m: name 'degrees_c' is not defined" + ] + } + ], "source": [ "degrees_c" ] @@ -720,7 +949,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "8d6408c9", "metadata": { "colab": { @@ -729,7 +958,15 @@ "id": "8d6408c9", "outputId": "81da20d0-3622-4c9e-8aac-57ee1be6dbf9" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 212.0\n" + ] + } + ], "source": [ "# boiling_c is a global variable\n", "boiling_c = 100\n", @@ -789,7 +1026,7 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python-env (3.11.14)", "language": "python", "name": "python3" }, @@ -803,7 +1040,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" }, "rise": { "scroll": true, diff --git a/01_materials/slides/04_strings.ipynb b/01_materials/slides/04_strings.ipynb index 8641eeb3e..70e6839ee 100644 --- a/01_materials/slides/04_strings.ipynb +++ b/01_materials/slides/04_strings.ipynb @@ -252,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f798ecd5", "metadata": { "colab": { @@ -262,7 +262,18 @@ "id": "f798ecd5", "outputId": "ef00a60a-3e44-4415-f36c-d2bdf25e2fe1" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"This string won't result in an error thanks to the escape sequence\"" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'This string won\\'t result in an error thanks to the escape sequence'" ] @@ -291,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "4e36d1f4", "metadata": { "colab": { @@ -301,7 +312,18 @@ "id": "4e36d1f4", "outputId": "b8e57f97-1c4e-4a47-acd0-f81bfa38210c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'hello world'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# adding strings together concatenates them\n", "'hello' + ' ' + 'world'" @@ -309,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "69d734a3", "metadata": { "colab": { @@ -319,15 +341,26 @@ "id": "69d734a3", "outputId": "819999ca-6460-4588-ed16-8da34c4ebae4" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'ha ha ha '" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# multiplying a string repeats it\n", - "'ha' * 3" + "('ha' + ' ') * 3" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "444cd7f1", "metadata": { "colab": { @@ -337,7 +370,19 @@ "id": "444cd7f1", "outputId": "2c58cc3f-dc2e-44cc-81e1-d467bef8db4e" }, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"int\") to str", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# mixing data types results in an error\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[33;43m'\u001b[39;49m\u001b[33;43mThe year is \u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2020\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], "source": [ "# mixing data types results in an error\n", "'The year is ' + 2020" @@ -357,7 +402,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "b922b788", "metadata": { "colab": { @@ -366,14 +411,25 @@ "id": "b922b788", "outputId": "a40e63ee-89bb-479e-dc21-c04b53502d2b" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'apple' == 'Apple'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "5f0f4faa", "metadata": { "colab": { @@ -382,14 +438,25 @@ "id": "5f0f4faa", "outputId": "3c0a30f0-dc4b-4a93-f1f0-d89a8806cd5a" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'apple' != 'Apple'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "1158f00c", "metadata": { "colab": { @@ -398,7 +465,18 @@ "id": "1158f00c", "outputId": "a88646b6-af0a-4100-fcfe-e3439a3097cd" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'20' == 20" ] @@ -432,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "c231d8f4", "metadata": { "colab": { @@ -441,13 +519,21 @@ "id": "c231d8f4", "outputId": "c98c26a1-0f5f-417a-e0dc-7335d7f31491" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Initials are A.L.\n" + ] + } + ], "source": [ "first_name = 'Ada'\n", "last_name = 'Lovelace'\n", "\n", "# print initials\n", - "print('Initials are', first_name[0], last_name[0])" + "print('Initials are', (first_name[0] + '.' + last_name[0] + '.'))" ] }, { @@ -462,7 +548,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "2a8ab4a2", "metadata": { "colab": { @@ -471,14 +557,22 @@ "id": "2a8ab4a2", "outputId": "d8ba7212-f7fb-45ea-d702-a650a66063ef" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A lace\n" + ] + } + ], "source": [ "print(first_name[:1], last_name[4:])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "474b7246", "metadata": { "colab": { @@ -488,7 +582,18 @@ "id": "474b7246", "outputId": "0eab5c5c-1800-4285-8634-dc4d14e2f017" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'555'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "phone_number = '+1 555-123-4567'\n", "\n", @@ -508,7 +613,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "41ee9c63", "metadata": { "colab": { @@ -518,7 +623,18 @@ "id": "41ee9c63", "outputId": "a28e1821-c5d8-49d7-8eb9-0f5efced5092" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'4567'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "phone_number[-4:]" ] @@ -534,12 +650,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "a6c3691a", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5.666666666666667\n" + ] + }, + { + "data": { + "text/plain": [ + "'lifrag'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code goes here" + "# Your code goes here\n", + "word = 'supercalifragilisticexpialidocious'\n", + "\n", + "len(word)\n", + "print(34/6)\n", + "\n", + "word[7:13]" ] }, { @@ -556,7 +696,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "052d6727", "metadata": { "id": "052d6727" @@ -568,7 +708,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "22261d43", "metadata": { "colab": { @@ -577,14 +717,25 @@ "id": "22261d43", "outputId": "98df15ab-64db-4b14-ad0e-3b760beccdc1" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'R' in job_qualifications" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "0345fd67", "metadata": { "colab": { @@ -593,14 +744,25 @@ "id": "0345fd67", "outputId": "26583257-42da-4bab-b326-c7249f67c613" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "' r ' in job_qualifications" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "c54f65ef", "metadata": { "colab": { @@ -609,7 +771,18 @@ "id": "c54f65ef", "outputId": "ede4fcad-d092-46d1-a1ca-ffa1f8a8bec5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'JavaScript' in job_qualifications" ] @@ -626,10 +799,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "0556df8e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 fish, 2 fish\n" + ] + } + ], "source": [ "# We can print strings, ints, and floats together\n", "print(1, 'fish,', 2, 'fish')" @@ -637,10 +818,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "6a7903e2", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "len('Sometimes we type long-winded sentences to meet word counts or character counts.')" ] @@ -668,10 +860,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "6cee9074", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLING'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# convert a string to all caps\n", "'I am not yelling'.upper()" @@ -679,10 +882,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "2c7eafdf", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# count the 'e's\n", "'This string is unusual'.count('e')" @@ -690,10 +904,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "9e016ebe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# check if a string ends with a substring\n", "'file_name.csv'.endswith('.csv')" @@ -701,10 +926,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "a9beef6b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'long_file_name_with_spaces.csv'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# replace text\n", "'long file name with spaces.csv'.replace(' ', '_')" @@ -730,10 +966,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "5ae0487a", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "first_name = 'Ada'\n", "last_name = 'Lovelace'\n", @@ -751,10 +998,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "id": "05e7baca", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "f'Ada Lovelace\\'s initials are {first_name[0]}. {last_name[0]}.'" ] @@ -780,10 +1038,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "31fed757", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method_descriptor:\n", + "\n", + "lower(self, /) unbound builtins.str method\n", + " Return a copy of the string converted to lowercase.\n", + "\n" + ] + } + ], "source": [ "help(str.lower)" ] @@ -806,7 +1076,7 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python-env (3.11.14)", "language": "python", "name": "python3" }, @@ -820,7 +1090,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" }, "rise": { "scroll": true, diff --git a/01_materials/slides/07_control_flow.ipynb b/01_materials/slides/07_control_flow.ipynb index ccf1abbbe..bcdf37f7d 100644 --- a/01_materials/slides/07_control_flow.ipynb +++ b/01_materials/slides/07_control_flow.ipynb @@ -256,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "2dbfb92a", "metadata": { "colab": { @@ -265,14 +265,25 @@ "id": "2dbfb92a", "outputId": "e1324eaf-822e-4ef2-e64b-de51cf0c1b1f" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'Python' == 'python' or True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "92880290", "metadata": { "colab": { @@ -281,7 +292,18 @@ "id": "92880290", "outputId": "454d8067-6d07-43dd-d911-e10114793c60" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "not (7 % 2 == 1) or False" ] @@ -410,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "df30db67", "metadata": { "colab": { @@ -419,7 +441,15 @@ "id": "df30db67", "outputId": "001e0d5c-d1ee-409c-b8bf-5f1c30b9ee7a" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], "source": [ "year = 2022\n", "\n", @@ -474,7 +504,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "1f623bb3", "metadata": { "colab": { @@ -483,7 +513,15 @@ "id": "1f623bb3", "outputId": "acdb38de-1bd8-4a8d-f9cf-6be1e99cf717" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 19th century.\n" + ] + } + ], "source": [ "year = 1867\n", "\n", @@ -515,12 +553,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "a014bfd8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "it's really hot!\n" + ] + } + ], "source": [ - "# Your code goes here" + "# Your code goes here\n", + "temp = 32\n", + "\n", + "if temp > 45:\n", + " print('it\\'s extremely hot!')\n", + "elif temp >= 31:\n", + " print('it\\'s really hot!')\n", + "elif temp >= 16:\n", + " print('it\\'s hot!')\n", + "elif temp >= 1:\n", + " print('it\\'s cold!')\n", + "else: \n", + " print('it\\'s freezing!')" ] }, { @@ -3210,7 +3268,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python-env (3.11.14)", "language": "python", "name": "python3" }, @@ -3224,7 +3282,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.14" }, "rise": { "scroll": true, diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 1ae6fe242..210713bfd 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -76,7 +76,134 @@ "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "\n", + "0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n", + "\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n", + "\n" + ] + } + ], "source": [ "all_paths = [\n", " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", @@ -95,8 +222,10 @@ "\n", "with open(all_paths[0], 'r') as f:\n", " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " rows = f.readlines() # read all lines from the csv file into a list\n", + " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n", + " for row in rows:\n", + " print(row)" ] }, { @@ -130,14 +259,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": { "id": "82-bk4CBB1w4" }, "outputs": [], "source": [ - "import numpy as np\n", - "\n", "def patient_summary(file_path, operation):\n", " data = np.loadtxt(fname=file_path, delimiter=',') # Load the data from the file\n", " ax = 1 # This specifies that the operation should be done for each row (patient)\n", @@ -145,13 +281,13 @@ " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n", - "\n", + " summary_values = np.mean(data, axis=ax) # since the summary value is for EACH patient, we ensure that the axis = ax, which is 1.\n", " elif operation == 'max':\n", " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.max(data, axis=ax)\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.min(data, axis=ax)\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", @@ -161,11 +297,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -228,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "_svDiRkdIwiT" }, @@ -261,15 +405,23 @@ "\n", "def detect_problems(file_path):\n", " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", - "\n", - " return" + " means = patient_summary(file_path, 'mean') # get mean inflammation score for each of the 60 patients using our patient_summary function\n", + " return check_zeros(means) # pass the means array to check_zeros(), which returns Ture if any values = 0 (problem detected) and False otherwise." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", @@ -314,7 +466,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env (3.11.14)", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +480,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4,