diff --git a/04_this_cohort/live-code/11_26_2025.ipynb b/04_this_cohort/live-code/11_26_2025.ipynb new file mode 100644 index 000000000..104c8d415 --- /dev/null +++ b/04_this_cohort/live-code/11_26_2025.ipynb @@ -0,0 +1,1248 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "id": "c400ce4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "6d15bb20", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 + 0" + ] + }, + { + "cell_type": "markdown", + "id": "1b150756", + "metadata": {}, + "source": [ + " - `Shift + Enter`: Run the current cell and move to the next cell.\n", + " - `Ctrl + Enter`: Run the current cell and stay on the same cell.\n", + " - `Alt + Enter`: Run the current cell and insert a new cell below." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "c1d78b69", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello!\n" + ] + } + ], + "source": [ + "print(\"hello!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8839bafe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hi!\n" + ] + } + ], + "source": [ + "print(\"hi!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "3d38a859", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "goodbye!\n" + ] + } + ], + "source": [ + "print(\"goodbye!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "aa59179a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bye!\n" + ] + } + ], + "source": [ + "print(\"bye!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "89626de2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first live learning session!\n" + ] + } + ], + "source": [ + "print(\"first live learning session!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "af974aa1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# integers (int) are whole numbers\n", + "\n", + "5 + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a7c33a0f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# floating point (float) are decimal numbers\n", + "\n", + "5 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "760e7fb4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(5 / 2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85e4c937", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 // 3 # integer division (always rounding down)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f845bb1f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55812b4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 % 3 # modulo or remainder" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "69ab6c3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + }, + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(1 + 1)\n", + "10 ** 3 # exponentiation" + ] + }, + { + "cell_type": "markdown", + "id": "afec1d08", + "metadata": {}, + "source": [ + "| Operator | Description |\n", + "| --- | --- |\n", + "| `>` | Greater than |\n", + "| `>=` | Greater than or equal to |\n", + "| `<` | Less than |\n", + "| `<=` | Less than or equal to |\n", + "| `==` | Equal to |\n", + "| `!=` | Not equal to |" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "00af980c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "50 > 25" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "18068b17", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-15 >= - 14.99" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5072a136", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 == 20" + ] + }, + { + "cell_type": "markdown", + "id": "0a950f66", + "metadata": {}, + "source": [ + "| Order | Operator | Description |\n", + "|---|---|---|\n", + "| 1 | `**` | Exponentiation |\n", + "| 2 | `-`| Negation |\n", + "| 3 | `*`, `/`, `//`, `%` | Multiplication, division, integer division, and modulo |\n", + "| 4 | `+`, `-` | Addition and subtraction |\n", + "| 5 | `<`, `<=`, `>`, `>=`, `==`, `!=` | Less than, less than or equal to, greater than, greater than or equal to, equal, not equal |" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "c15ece65", + "metadata": {}, + "outputs": [], + "source": [ + "# can include digits, letters, and underscores\n", + "# cannot start with a digit\n", + "# are case sensitive\n", + "\n", + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "4a27a017", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "aa482540", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "440e601d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "0a5fa1ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(9 / 5) * 25 + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "93d1cc1b", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "f1e0083a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "c1030808", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "67cc65fc", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "2eb6ba2f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "9a51098f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "64ccfc66", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = degrees_celsius + 10 # 0 + 10" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "18660925", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "8049f1a3", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "698fe0ef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "23983056", + "metadata": {}, + "outputs": [], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "cf4f8c23", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "e92330f6", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "e1342150", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "c0c412ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25a1b50a", + "metadata": {}, + "outputs": [], + "source": [ + "# degrees_celsius = degrees_celsius + 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3bea5001", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-10" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = 0\n", + "degrees_celsius -= 10 # degrees_celsius = degrees_celsius - 10\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "0a753611", + "metadata": {}, + "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[56]\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" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "2f1378eb", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (934255472.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[57]\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 -" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "698e0c86", + "metadata": {}, + "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[58]\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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e52d6ccc", + "metadata": {}, + "outputs": [], + "source": [ + "# this is a comment!" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "2aabe068", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "600f5353", + "metadata": {}, + "outputs": [], + "source": [ + "no_cats = 60\n", + "no_dogs = 70\n", + "no_fish = 80\n", + "tot_animals = (no_cats \n", + " + no_dogs \n", + " + no_fish)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "f2734c5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "210" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tot_animals" + ] + }, + { + "cell_type": "markdown", + "id": "011aa018", + "metadata": {}, + "source": [ + "Version 1\n", + "```python\n", + "studentone_grade=90\n", + "StudentGrade2=50\n", + "stu3gr=74\n", + "avggrade=(studentone_grade+StudentGrade2+stut3gr)/3\n", + "```\n", + "\n", + "Version 2 \n", + "```python\n", + "student1_grade = 90\n", + "student2_grade = 50\n", + "student3_grade = 74\n", + "average_grade = ((student1_grade\n", + " + student2_grade\n", + " + student3_grade)\n", + " / 3)\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "0cb5f0e1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "it is Tuesday!\n" + ] + } + ], + "source": [ + "print(\"it is Tuesday!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "1a202f57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "58e2dda6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-43)" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "0c0a7950", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "c35bf94e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "55a50e3f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.99)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "bba25b06", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print(abs(round(-2 * 1.5)))" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "2323f93e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print(abs(round(-2 * 1.5)))" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "c3caa06a", + "metadata": {}, + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "3105f39b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.556" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.5555555, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "544b046b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.5555555)" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "c276f64a", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " degrees_f = (9 / 5) * degrees_c + 32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "76d39831", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "fbadb263", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "c146ab87", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "302.0" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(150)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0f280034", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}