diff --git a/04_this_cohort/live-code/03_04_2026.ipynb b/04_this_cohort/live-code/03_04_2026.ipynb new file mode 100644 index 000000000..4c18155c9 --- /dev/null +++ b/04_this_cohort/live-code/03_04_2026.ipynb @@ -0,0 +1,2143 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 54, + "id": "1a70cd9c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6" + ] + }, + { + "cell_type": "markdown", + "id": "f1d4491f", + "metadata": {}, + "source": [ + " - Utilize keyboard shortcuts for faster execution:\n", + " - `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": 55, + "id": "82d32402", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 + 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93dfb8c1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "a59c4d57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 + 3" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "aa692a5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 + 4" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "ba6a2053", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello!\n" + ] + } + ], + "source": [ + "print(\"hello!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "4a0584a1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "goodbye!\n" + ] + } + ], + "source": [ + "print(\"goodbye!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "d6a9bda3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6 # int -> whole numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "55672bbe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "23.1" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "11.0 + 12.1 # float -> decimal number" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "49bdbdcb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 5" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "3fe37c24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "d64fb436", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# integer division \n", + "# divide first operand by second & return quotient rounded down to nearest integer\n", + "\n", + "10 // 3" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "b08809e8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# modulo operator\n", + "# return the remainder of the division of the first operand by the second\n", + "\n", + "10 % 3" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "4ec2d5e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# exponentiation\n", + "# raising a number to a power\n", + "\n", + "10 ** 3" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "3c64a4bd", + "metadata": {}, + "outputs": [], + "source": [ + "# bool\n", + "# True or False" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "1126b873", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "50 > 25" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "af1b5e0b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-15 >= -14.99" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "8ec9fcc2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 == 20" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "1122c5df", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 != 20" + ] + }, + { + "cell_type": "markdown", + "id": "672d8698", + "metadata": {}, + "source": [ + "## Operator precedence\n", + "\n", + "Arithmetic and comparison operators are evaluated in the following order. We can enclose operations in parentheses to override the order of precedence -- operations in parentheses are evaluated before the rest of the expression.\n", + "\n", + "| 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": 72, + "id": "9ea9a271", + "metadata": {}, + "outputs": [], + "source": [ + "# negation: unary operation that changes the sign of a number\n", + "# subtraction: binary operation, subtract one value from another" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "344b4731", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 - 3" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "04766585", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-5" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-5" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "ea7ba44e", + "metadata": {}, + "outputs": [], + "source": [ + "# variable names\n", + "\n", + "# letters, digits, and underscore\n", + "# cannot start with a digit\n", + "# case sensitive" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "856923a6", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "47c51a25", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "d9916987", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "f17548be", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "70fe10df", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(9 / 5) * 25 + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "33c537c9", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "5e87b1e6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "ad068776", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "4c56a0d7", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie_cups = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "b2515677", + "metadata": {}, + "outputs": [], + "source": [ + "total_cups = kaylie_cups + 10" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "a406f028", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_cups" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "91575d73", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_cups" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "cf9abc95", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie_cups = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "a9c36e1c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_cups" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "dc6d7581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_cups" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "1b8392e5", + "metadata": {}, + "outputs": [], + "source": [ + "total_cups = kaylie_cups + 10" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "77b40083", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_cups" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6f1d28a2", + "metadata": {}, + "outputs": [], + "source": [ + "# we can reassign a variable, and that will change the value which that variable refers to\n", + "\n", + "# BUT reassigning a varibale does not change any other variable" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "36c5c361", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7eb520e3", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = degrees_celsius + 10 # 0 + 10 = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "53a50195", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "4be52bbb", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "4b0ded9f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "065684a5", + "metadata": {}, + "outputs": [], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "722f5d8e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "9f2291aa", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "48a2863c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "22b7f67a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "7be03346", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks = 4" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "2bd2f8cf", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks = no_of_weeks + 10 # 4 + 10 = 14" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "551e062d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "no_of_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9f51ec60", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks += 10 # 14 + 10 = 24" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7a562ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "no_of_weeks\n", + "\n", + "# line 104 does the same thing as 106, just in a more concise way - augmented assignment" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "abc61665", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = 0\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "af053dc8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-10" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius -= 10\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "deadccc7", + "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[110]\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": 111, + "id": "77db54aa", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (1720778857.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[111]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m12 -\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], + "source": [ + "12 - " + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "f0f83339", + "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[112]\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": 113, + "id": "c747e691", + "metadata": {}, + "outputs": [], + "source": [ + "# This is a comment" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be1e8f07", + "metadata": {}, + "outputs": [], + "source": [ + "# white space:\n", + "# a space on either side of an operand\n", + "# split code across multiple lines by wrapping it in parentheses" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "4c2acf75", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "35607feb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "600000000" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(100000000 + \n", + " 500000000)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1eaf0f06", + "metadata": {}, + "outputs": [], + "source": [ + "# comments:\n", + "# explain your code and plan future work in plain language\n", + "# toggle lines of code on/off during debugging" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "dcaea917", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie_vacations = 30\n", + "kaylie_vacations = kaylie_vacations + 10\n", + "kaylie_vacations = kaylie_vacations - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "id": "e8d01da5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "39" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_vacations" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8467248", + "metadata": {}, + "outputs": [], + "source": [ + "# clear and consistent variable names\n", + "# descriptive\n", + "# consistent naming\n", + "\n", + "dog1 = 'Penny'\n", + "dog_2 = 'Boone'\n", + "dog_three = 'Bailey'" + ] + }, + { + "cell_type": "markdown", + "id": "bd6855aa", + "metadata": {}, + "source": [ + "\n", + "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", + "```\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "708f48ec", + "metadata": {}, + "outputs": [], + "source": [ + "# function is a named block of code that performs a specific task\n", + "# take zero or more input values and produce one or more return values" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "3bf0fb49", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "print(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "id": "330a3055", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "42" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "42" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "id": "ac62f318", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "10df3380", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-43)" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "id": "30e9049f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.99)" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "id": "c231b104", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7.0" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(7)" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "9fd67425", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "1f4a1945", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2/3" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "bfd83c12", + "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": 133, + "id": "f10992b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6667" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3, 4)" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "id": "dff320b6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "24\n" + ] + } + ], + "source": [ + "print(round(abs(-16) * 1.5))" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "id": "71f3592f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-16)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "id": "812e286f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(16 * 1.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "id": "63074862", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "24\n" + ] + } + ], + "source": [ + "print(24)" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "c1c574f9", + "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": 142, + "id": "1e5b858a", + "metadata": {}, + "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[142]\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" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "id": "a97c6a66", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 148, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed267610", + "metadata": {}, + "outputs": [], + "source": [ + "# parameters\n", + "# placeholders for the values that will be provided when the function is called\n", + "# local variables within the function, only accessible inside function's code block\n", + "\n", + "# argument\n", + "# actual value that is passed to the function when it is called\n", + "# correspond to the parameters in the function definition and provide the data for the \n", + "# function to work on" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "id": "66ccbada", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "id": "7b986ddb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "id": "8557f1dc", + "metadata": {}, + "outputs": [], + "source": [ + "weather_today = 100" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "0754b422", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "100" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "weather_today" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "id": "a1b6334a", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_c = 1000" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "7e68a674", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 146, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_c" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "97d4d8a5", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, divisor):\n", + " output = dividend / divisor\n", + " return output" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "216ec586", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20.0" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(100, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "e3089e3c", + "metadata": {}, + "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[151]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m100\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[149]\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 output = \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mdivisor\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m output\n", + "\u001b[31mZeroDivisionError\u001b[39m: division by zero" + ] + } + ], + "source": [ + "divide(100, 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "id": "7f44c90c", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_sales_tax(price, tax_rate=0.13):\n", + " tax_amt = price * tax_rate\n", + " return tax_amt" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "id": "f47ad5be", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.9500000000000002" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(15)" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "id": "043aa1af", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.9500000000000002" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "15 * 0.13" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "id": "1169b55d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5, 0.08)" + ] + }, + { + "cell_type": "code", + "execution_count": 157, + "id": "fc7791e0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 157, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 * 0.08" + ] + }, + { + "cell_type": "code", + "execution_count": 158, + "id": "3506b6ad", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate=0.13, tip_rate=0.15):\n", + " tax_amt = price * tax_rate\n", + " tip_amt = price * tip_rate\n", + " return price + tax_amt + tip_amt" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "9df4bd19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "id": "d0e03276", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 160, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 * 0.13 + 100 * 0.15 + 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d64a6de7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, 0.18) # wanted to tip 18%" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "id": "f2eaae24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 162, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.18 + 100 * 0.15" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "33d438ee", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "131.0" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, tip_rate=0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "id": "8ffaf340", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "131.0" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.13 + 100 * 0.18" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "id": "65dc68b9", + "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": 166, + "id": "dd807ab3", + "metadata": {}, + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "id": "1a2f5435", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " \"\"\"Convert degrees from Celsius to Fahrenheit\"\"\"\n", + " return ((9 / 5) * degrees_c + 32)" + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "id": "f87d4a33", + "metadata": {}, + "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": [ + "help(c_to_f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f758a788", + "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 +}