diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 156d0408e..e5621ca5e 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -26,10 +26,10 @@ " * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n", "\n", "Checklist:\n", - "- [ ] Created a branch with the correct naming convention.\n", - "- [ ] Ensured that the repository is public.\n", - "- [ ] Reviewed the PR description guidelines and adhered to them.\n", - "- [ ] Verify that the link is accessible in a private browser window.\n", + "- [*] Created a branch with the correct naming convention.\n", + "- [*] Ensured that the repository is public.\n", + "- [*] Reviewed the PR description guidelines and adhered to them.\n", + "- [*] Verify that the link is accessible in a private browser window.\n", "\n", "If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#dc-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges." ] @@ -56,32 +56,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", - "\n", + " return sorted(word_a.lower()) == sorted(word_b.lower())\n", + " \n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,22 +130,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " if is_case_sensitive:\n", + " return sorted(word_a) == sorted(word_b)\n", + " else:\n", + " return sorted(word_a.lower()) == sorted(word_b.lower())\n", "\n", "# Run your code to check using the words below:\n", + "# [PR] this is where I realized why we started with non-case-sensitive anagrams, despite it being more complicated\n", + "# [PR] tried to add descriptive strings in addition to the boolean T/F, but after struggling a bit, decided to just follow the instructions\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -130,7 +190,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +204,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/04_this_cohort/live_code/08_19_2025.ipynb b/04_this_cohort/live_code/08_19_2025.ipynb new file mode 100644 index 000000000..0936ab34c --- /dev/null +++ b/04_this_cohort/live_code/08_19_2025.ipynb @@ -0,0 +1,1569 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "3a708ea8", + "metadata": {}, + "source": [ + "# Python\n", + "## August 19th 2025" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "ef084562", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World\n" + ] + } + ], + "source": [ + "print('Hello World')" + ] + }, + { + "cell_type": "markdown", + "id": "07bc5265", + "metadata": {}, + "source": [ + "**Keyboard Shortcuts:**\n", + " - 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": 82, + "id": "668637e4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World\n" + ] + } + ], + "source": [ + "print('Hello World')" + ] + }, + { + "cell_type": "markdown", + "id": "f3171117", + "metadata": {}, + "source": [ + "- int: whole numbers\n", + "- float: decimal numbers\n", + "- string: text\n", + "- bool: true/false" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "afe3c287", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "4f88bc62", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "13495679", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "16e44314", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# integer division -> divide the first operand by the second and return the quotient rounded down to the nearest int\n", + "10 // 3" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "4c6f4a58", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# modulo -> return the remainder of the division of the first operand by the second\n", + "10 % 3" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "5e68b158", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 ** 3 " + ] + }, + { + "cell_type": "markdown", + "id": "2082c9cb", + "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": 89, + "id": "e3a300f0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "be88cf56", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "False" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "f00fae10", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "50 > 25" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "36fcfc66", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-15 >= -14.99" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "4d4baf68", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 == 20" + ] + }, + { + "cell_type": "markdown", + "id": "77effa12", + "metadata": {}, + "source": [ + "\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": 94, + "id": "afe5d9ed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(10 * 2) / 3 > 15" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "1c7c767d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "0bb7aae0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.666666666666667" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "3eb8eb8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "6.666666666666667 > 15" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "992957e4", + "metadata": {}, + "outputs": [], + "source": [ + "# variable names\n", + "# can have letters, digits, and underscores\n", + "# cannot start with a digit\n", + "# case sensitive\n", + "\n", + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "cb75ef25", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32\n", + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "1712855b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(9 / 5) * 25 + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "5e4c6a19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = 0\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "ad95dc26", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "a672812c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32\n", + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "1e58c58f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "20df63a5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = degrees_celsius + 10\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "aeab4d73", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "a537cef5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "d676653d", + "metadata": {}, + "outputs": [], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "id": "b68e00aa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "d250e226", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "id": "a3ce84c8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "27ad2700", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "13ca91ce", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "832bb8d7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# degrees_celsius = degrees_celsius + 10\n", + "\n", + "# augmented assignment\n", + "degrees_celsius += 10\n", + "degrees_celsius\n", + "\n", + "# degrees_celsius **= 10" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "18d23121", + "metadata": {}, + "outputs": [], + "source": [ + "julia = 'cheese sandwich'\n", + "kaylie = julia" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "id": "9bfcf134", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "id": "8912a684", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "c4ef4583", + "metadata": {}, + "outputs": [], + "source": [ + "julia = 'ham sandwich'" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "id": "9cc7280d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ham sandwich'" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "id": "0ad8fb10", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "0bde7350", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie = julia" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "db32f129", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ham sandwich'" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "ebfca44f", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "cannot assign to literal here. Maybe you meant '==' instead of '='? (3541004665.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[132], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 12 = x\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m cannot assign to literal here. Maybe you meant '==' instead of '='?\n" + ] + } + ], + "source": [ + "12 = x" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "id": "b8283460", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (934255472.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[133], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 25 -\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "25 -" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "id": "3d3b241c", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'my_variable' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[134], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmy_variable\u001b[49m \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m\n", + "\u001b[0;31mNameError\u001b[0m: name 'my_variable' is not defined" + ] + } + ], + "source": [ + "my_variable + 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "02d5313a", + "metadata": {}, + "outputs": [], + "source": [ + "# this is a comment!\n", + "\n", + "dog = 'woof'\n", + "# dog = 'bark'\n", + "cat = 'meow'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e3384b06", + "metadata": {}, + "outputs": [], + "source": [ + "# readability\n", + "\n", + "# white space: space to either side of an operator helps with readability\n", + "# can split code across multiple lines by wrapping it in parentheses\n", + "\n", + "# comments: help explain sections of code\n", + "# can toggle lines of code on/off\n", + "\n", + "# clear and consistent variable names: descriptive variable names\n", + "# consistent naming practice" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "id": "352cd1da", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 138, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(5 + 5 +\n", + " 5 + 5)" + ] + }, + { + "cell_type": "markdown", + "id": "960de3e0", + "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", + "```\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2ac4eae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "# function: block of code that performs a task\n", + "# can take zero or more inputs and return an output\n", + "\n", + "print(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "id": "f7c97d25", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "id": "549350d7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "bool" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(True)" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "id": "8054647d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-43)" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "ba5e2c18", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "4de0a0f6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 146, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "a9ee0753", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4.0" + ] + }, + "execution_count": 147, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(4)" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "id": "5cb855cf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 148, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(4.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "38734581", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(round(2 * 1.5))" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "b57533e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 * 1.5" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "367b194d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "id": "b0f10f1d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "id": "a2911504", + "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": 161, + "id": "cee2fa40", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.66667" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34a135e0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "id": "2f0e2761", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 / 3 " + ] + }, + { + "cell_type": "code", + "execution_count": 157, + "id": "07e074d6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 157, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(10/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "dc267146", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7950db8b", + "metadata": {}, + "outputs": [], + "source": [ + "# function names:\n", + "# can use letters, digits, and underscores\n", + "# cannot start with a digit\n", + "# case sensitive\n", + "# typically functions start with lowercase letters\n", + "\n", + "\n", + "# parameters: variables used only within a function\n", + "# pass an argument to a function, argument value is assigned to a corresponding parameter\n", + "\n", + "# None: special data type representing no data\n", + "# if we don't have a return statement, Python will fill in an implicit one and return None" + ] + }, + { + "cell_type": "code", + "execution_count": 169, + "id": "488a0cd2", + "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": 163, + "id": "3c64200c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "id": "6a569714", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)" + ] + }, + { + "cell_type": "code", + "execution_count": 170, + "id": "38c9d40f", + "metadata": {}, + "outputs": [], + "source": [ + "boiling_f = c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 171, + "id": "e2ef8f99", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 171, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "boiling_f" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "id": "b1a72385", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " degrees_f = (9 / 5) * degrees_c + 32\n", + " print(degrees_f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ac52ac1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "212.0\n" + ] + } + ], + "source": [ + "boiling_f = c_to_f(100) # output is None" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "id": "c021b747", + "metadata": {}, + "outputs": [], + "source": [ + "boiling_f" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f8eb2d2", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/04_this_cohort/live_code/08_20_2025.ipynb b/04_this_cohort/live_code/08_20_2025.ipynb new file mode 100644 index 000000000..a14965013 --- /dev/null +++ b/04_this_cohort/live_code/08_20_2025.ipynb @@ -0,0 +1,2649 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "9d0ff086", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "# August 20, 2025\n", + "\n", + "print(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "030b58ec", + "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": 3, + "id": "85a87410", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "9a976f8d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "39.2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(4.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "901e070c", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, divisor):\n", + " result = dividend / divisor\n", + " return int(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "3e58d32f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(0, 2) # 0 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9183bf0", + "metadata": {}, + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[0;32mIn[5], line 2\u001b[0m, in \u001b[0;36mdivide\u001b[0;34m(dividend, divisor)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdivide\u001b[39m(dividend, divisor):\n\u001b[0;32m----> 2\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdivisor\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" + ] + } + ], + "source": [ + "divide(2, 0) # 2 / 0" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "68afd840", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_sales_tax(price, tax_rate=0.13):\n", + " tax_amount = price * tax_rate\n", + " return tax_amount" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "ab003d7a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "45b97958", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 * 0.13" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1e266d6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5, 0.08)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "8ca927fd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 * 0.08" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "be6e8d78", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate=0.13, tip_rate=0.15):\n", + " tax_amount = price * tax_rate\n", + " tip_amount = price * tip_rate\n", + " total_bill = price + tax_amount + tip_amount\n", + " return total_bill" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "127e67c3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "c2cd3752", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.13 + 100 * 0.15" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "42fa3953", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "135.0" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, 0.20)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "7ba15f90", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "135.0" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.20 + 100 * 0.15" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82ec6fef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, tip_rate=0.20)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "cf065dd9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.13 + 100 * 0.20" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "6836f7db", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill_2(price, tax_rate, tip_rate):\n", + " tax_amount = price * tax_rate\n", + " tip_amount = price * tip_rate\n", + " total_bill = price + tax_amount + tip_amount\n", + " return total_bill" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "90ed654b", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "calc_total_bill_2() missing 2 required positional arguments: 'tax_rate' and 'tip_rate'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[28], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mcalc_total_bill_2\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: calc_total_bill_2() missing 2 required positional arguments: 'tax_rate' and 'tip_rate'" + ] + } + ], + "source": [ + "calc_total_bill_2(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "8e823957", + "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": 30, + "id": "b79cb63b", + "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": 31, + "id": "843b9931", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " \"\"\"Convert degrees from Celsius to Fahrenheit\"\"\"\n", + " degrees_f = (9 / 5) * degrees_c + 32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "6245fa70", + "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": 33, + "id": "9e781f6c", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'degrees_c' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[33], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdegrees_c\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'degrees_c' is not defined" + ] + } + ], + "source": [ + "degrees_c" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "69237183", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie = 'loves python'" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "a39b5a2e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'loves python'" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "6dfd2533", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'This is a string'" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "448e0c00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This is also a string'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"This is also a string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "542265a7", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unterminated string literal (detected at line 1) (3110063236.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[38], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 'This does not work\"\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 1)\n" + ] + } + ], + "source": [ + "'This does not work\"" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "e71ab187", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unterminated string literal (detected at line 1) (3205553238.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[39], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 'Let's see if this works'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 1)\n" + ] + } + ], + "source": [ + "'Let's see if this works'" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "6a0295f8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Let's see if this works\"" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Let's see if this works\"" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "f089e2d3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nI am a multiline string\\n\\nThis is handy for long texts\\n'" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'''\n", + "I am a multiline string\n", + "\n", + "This is handy for long texts\n", + "'''" + ] + }, + { + "cell_type": "markdown", + "id": "19971831", + "metadata": {}, + "source": [ + "### Escape sequences\n", + "\n", + "| Escape sequence | Description |\n", + "|-----------------|--------------------|\n", + "| \\\\' | Single quote |\n", + "| \\\\\" | Double quote |\n", + "| \\\\\\\\ | Backslash |\n", + "| \\\\t | Tab |\n", + "| \\\\n | Newline |\n", + "| \\\\r | Carriage return |" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "b11e4eea", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a backslash: \\\n" + ] + } + ], + "source": [ + "print('This is a backslash: \\\\')" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "96ebbaad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a double-quote string with a quote inside: \"example\"\n" + ] + } + ], + "source": [ + "print('This is a double-quote string with a quote inside: \"example\"')" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "72c9916b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a double-quote string with a quote inside: \"example\"\n" + ] + } + ], + "source": [ + "print(\"This is a double-quote string with a quote inside: \\\"example\\\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "b55bf263", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a single-quoted string with a quote inside: won't\n" + ] + } + ], + "source": [ + "print(\"This is a single-quoted string with a quote inside: won't\")" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "10b4f1d1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a single-quoted string with a quote inside: won't\n" + ] + } + ], + "source": [ + "print('This is a single-quoted string with a quote inside: won\\'t')" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "79cb31aa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a return carriagee of \n" + ] + } + ], + "source": [ + "print('This is an example of \\ra return carriage')" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "551ba45d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "aaXXX\n" + ] + } + ], + "source": [ + "print('XXXXX\\raa')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7da855ec", + "metadata": {}, + "outputs": [], + "source": [ + "'aaXXX'" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "ef156d02", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "67345\n" + ] + } + ], + "source": [ + "print('12345\\r67')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e5ca326", + "metadata": {}, + "outputs": [], + "source": [ + "'67345'" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "3c0a2d47", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 + 3" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "419d1406", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "7798ad1a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello world'" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hello' + ' ' + 'world'" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "cd96116c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hahaha'" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'ha' * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "21834f6c", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"int\") to str", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[60], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mThe year is \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2025\u001b[39;49m\n", + "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "'The year is ' + 2025" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "37b09e1d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'apple' == 'Apple'" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "ad9f7ff1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'apple' != 'Apple'" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "109e656d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'20' == 20" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "3e2acc62", + "metadata": {}, + "outputs": [], + "source": [ + "first_name = 'Ada'\n", + "last_name = 'Lovelace'" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "80f7a91b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'A'" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "2bcfd2d1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'L'" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "f19b53ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ad'" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "9c77cfad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Lov'" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[0:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "3247e655", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'lace'" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[4:8]" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "1f05d5aa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'lace'" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "2caf3079", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Love'" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[:4]" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "ffd2da38", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'A'" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "c7d02351", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "9c5920bd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Aa'" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[::2]" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "feba273d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'oea'" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[1:7:2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1fc73262", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Le'" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[0:6:3] # start at index 1 to index 5, moving 3 at a time" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "3233e61a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'555'" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "phone_number = '+1 555-123-4567'\n", + "\n", + "phone_number[3:6]" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "0935ea8f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1 555-123'" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "phone_number[1:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "8c0fe64f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'15513'" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "phone_number[1:10:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "622dc5d2", + "metadata": {}, + "outputs": [], + "source": [ + "job_qualifications = 'The successful applicant will be proficient in R, Python, SQL, statistics'" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "1379e68e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'R' in job_qualifications" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "e9de6e9a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "' r ' in job_qualifications" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "460d26de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'JavaScript' in job_qualifications" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "1b509030", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 fish 2 fish\n" + ] + } + ], + "source": [ + "print(1, 'fish', 2, 'fish')" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "c4b3489d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len('Sometimes we have a lonnnnggg piece of text')" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "ce7765a2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'a', 'a', 'b', 'n', 'n']" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted('banana')" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "0db3344f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'k', 'l', 'y']" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted('kaylie')" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "701ee89f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLING'" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'I am not yelling'.upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "ee0786f1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'This string is unusual'.count('e')" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "12f8dcec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'file_name.csv'.endswith('.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "23b419dc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'long_file_name_with_spaces.csv'" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'long file name with spaces.csv'.replace(' ', '_')" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "c7c836bb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ada'" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "319764ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Lovelace'" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "63f3ae18", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Ada Lovelace\\'s initials are {}. {}.'.format(first_name[0], last_name[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "ed6ae208", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favourite veggie is lettuce'" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'My favourite veggie is {}'.format('lettuce')" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "id": "718d52c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f'Ada Lovelace\\'s initials are {first_name[0]}. {last_name[0]}.'" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "09c67c0a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favourite veggie is lettuce'" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f\"My favourite veggie is {'lettuce'}\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "186d20b7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favourite veggie is tomato'" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "veggie = 'tomato'\n", + "f'My favourite veggie is {veggie}'" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "id": "28655f0f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method_descriptor:\n", + "\n", + "lower(self, /)\n", + " Return a copy of the string converted to lowercase.\n", + "\n" + ] + } + ], + "source": [ + "help(str.lower)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ee48d03", + "metadata": {}, + "outputs": [], + "source": [ + "# int()\n", + "# if float -> truncate the decimal part\n", + "# if string representing a valid integer -> convert the string to an integer\n", + "# if string representing a float -> return error" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "id": "f08f6199", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(12.25)" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "4d8aad43", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int('2')" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "id": "575f3e74", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: '2.2222'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[121], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m2.2222\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '2.2222'" + ] + } + ], + "source": [ + "int('2.2222')" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "4422aefd", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: 'me'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[122], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mme\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'me'" + ] + } + ], + "source": [ + "int('me')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73c980dd", + "metadata": {}, + "outputs": [], + "source": [ + "# float()\n", + "# if int -> convert to a floating-point number\n", + "# if string representing a valid float -> convert the string to a float" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "863d7cea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "892.0" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(892)" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "7e9c4204", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "122.222" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float('122.222')" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "id": "98895e6d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "892.0" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float('892')" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "id": "34614738", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "could not convert string to float: 'me'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[125], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mme\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mValueError\u001b[0m: could not convert string to float: 'me'" + ] + } + ], + "source": [ + "float('me')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b1f46683", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'37.5'" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(37.5) #float to string" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a21c50f0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'29'" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(29) #int to string" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "764f5fd3", + "metadata": {}, + "outputs": [], + "source": [ + "# input() function prompt the user and return their response as a string" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "7050a4ce", + "metadata": {}, + "outputs": [], + "source": [ + "age = input(\"How old are you? \")" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "f4258dec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'10000000'" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "2ae59a8c", + "metadata": {}, + "outputs": [], + "source": [ + "fruit = input(\"What is your favourite fruit? \")" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "id": "95f035f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'kiwi'" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruit" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "id": "29e00786", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10000001" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age_next_year = int(age) + 1\n", + "age_next_year" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "id": "7a339668", + "metadata": {}, + "outputs": [], + "source": [ + "age = input(\"How old are you? \")" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "id": "9f6fa5c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cat'" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "id": "5edc2341", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: 'cat'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[137], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m age_next_year \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mage\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 2\u001b[0m age_next_year\n", + "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'cat'" + ] + } + ], + "source": [ + "age_next_year = int(age) + 1\n", + "age_next_year" + ] + }, + { + "cell_type": "markdown", + "id": "4af3f994", + "metadata": {}, + "source": [ + "## `not`\n", + "\n", + "|X|`not` X|\n", + "|-|-|\n", + "|True|False|\n", + "|False|True|" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "id": "8959f807", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 138, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# not:\n", + "# negate the truth value of the statement\n", + "\n", + "not True" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "id": "1b181857", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 139, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not False" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a0e55e0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 == 3" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "id": "6bc81c5a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (3 == 3)" + ] + }, + { + "cell_type": "markdown", + "id": "d89739d0", + "metadata": {}, + "source": [ + "## `and`\n", + "\n", + "Evaluates to `True` if both statements are true.\n", + "\n", + "|X|Y|X `and` Y|\n", + "|-|-|-|\n", + "|True|True|True|\n", + "|False|True|False|\n", + "|True|False|False|\n", + "|False|False|False|" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "id": "75bc5247", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 " + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "id": "5eeb52ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "32 > 9" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "525f159b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 and 32 > 9 # True and True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e4a025c", + "metadata": {}, + "outputs": [], + "source": [ + "# and: check if the statements on both sides are true" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "f62a8981", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 146, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0544ee19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 145, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python' and True # False and True" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "540f788c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_summer = True\n", + "is_sunny = True\n", + "is_summer and is_sunny # True and True" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "0dc91788", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "45 != 90 " + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "0c3b91ad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 > 5" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "id": "26aa4a0e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "45 != 90 and 20 > 5 # True and True" + ] + }, + { + "cell_type": "markdown", + "id": "69d408d2", + "metadata": {}, + "source": [ + "# To avoid confusion and to make sure you have consistent behaviour, you should always use boolean values (True and False) explicitly when working with logical operators." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3fbf0d88", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 153, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# and operator returns the first falsy value encountered or the last truthy value if all \n", + "# operands are true\n", + "\n", + "is_winter = \"True\" # non-empty string so it is considered a True (bool)\n", + "is_cloudy = True # True (bool))\n", + "\n", + "is_winter and is_cloudy" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "id": "ee22fafa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_cloudy and is_winter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0140c606", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cat'" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_pet = 'dog' # non-empty string so it is considered True (bool)\n", + "xindi_pet = 'cat' # non-empty string so it is considered True (bool)\n", + "\n", + "# 'dog' and 'cat'\n", + "my_pet and xindi_pet" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "id": "da71aa0e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dog'" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xindi_pet and my_pet" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c109dd78", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 157, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "day_of_week = 'Wednesday' # non-empty string so it is considered True (bool)\n", + "month = '' # empty string so it is considered False (bool)\n", + "\n", + "# '' and 'Wednesday'\n", + "month and day_of_week" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "aaac53a1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "False and True" + ] + }, + { + "cell_type": "code", + "execution_count": 158, + "id": "164ecc30", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 158, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "season = 'summer' # non-empty string so it is considered True (bool)\n", + "time_of_year = 0 # 0 so it is considered False (bool)\n", + "\n", + "season and 0" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/04_this_cohort/live_code/08_21_2025.ipynb b/04_this_cohort/live_code/08_21_2025.ipynb new file mode 100644 index 000000000..5da530ead --- /dev/null +++ b/04_this_cohort/live_code/08_21_2025.ipynb @@ -0,0 +1,1535 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "id": "36860799", + "metadata": {}, + "outputs": [], + "source": [ + "# August 21, 2025" + ] + }, + { + "cell_type": "markdown", + "id": "7fb0f1d5", + "metadata": {}, + "source": [ + "## `not`\n", + "\n", + "|X|`not` X|\n", + "|-|-|\n", + "|True|False|\n", + "|False|True|" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "833e8c5c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (3 == 3)" + ] + }, + { + "cell_type": "markdown", + "id": "e4cc2032", + "metadata": {}, + "source": [ + "## `and`\n", + "\n", + "Evaluates to `True` if both statements are true.\n", + "\n", + "|X|Y|X `and` Y|\n", + "|-|-|-|\n", + "|True|True|True|\n", + "|False|True|False|\n", + "|True|False|False|\n", + "|False|False|False|" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "61a17c2e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(4 > 1) and (2 == 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "85151bcc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(4 == 1) and (2 == 2)" + ] + }, + { + "cell_type": "markdown", + "id": "49ac662f", + "metadata": {}, + "source": [ + "## To avoid confusion and ensure consistent behaviour, it's recommended to use boolean values (`True` or `False`) explicitly when working with logical operations to ensure predictable outcomes based on boolean logic." + ] + }, + { + "cell_type": "markdown", + "id": "05657084", + "metadata": {}, + "source": [ + "## `or`\n", + "\n", + "Evaluates to `True` if just one of the statements is true.\n", + "\n", + "|X|Y|X `or` Y|\n", + "|-|-|-|\n", + "|True|True|True|\n", + "|False|True|True|\n", + "|True|False|True|\n", + "|False|False|False|" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "f7b847be", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python' or True" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "d3f1bad5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python'" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a9efd3c7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (7 % 2 == 1) or False" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e1df7477", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 % 2" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "b9620c57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 == 1" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "dba54401", + "metadata": {}, + "outputs": [], + "source": [ + "# and operator: return the first falsy value encountered or the last truthy value if all operands \n", + "# are `True` based on the conditions provided\n", + "\n", + "# or operator: return the first truthy value encountered or the last falsy value if all operands\n", + "# are `False` based on the conditions provided" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "486c4a6b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dog'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# \"dog\" is a non-empty string, True\n", + "# \"cat\" is a non-empty string, True\n", + "\n", + "\"dog\" or \"cat\" " + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "a55a4a8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 0 is False\n", + "\n", + "0 or 0" + ] + }, + { + "cell_type": "markdown", + "id": "33e284de", + "metadata": {}, + "source": [ + "## Operator precedence\n", + "\n", + "Boolean operators are evaluated after arithmetic and comparison operators.\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 |\n", + "| 6 | `not` | Not |\n", + "| 7 | `and` | And |\n", + "| 8 | `or` | Or|" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b2337bd5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True and True or False" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "ec888abe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True or False" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "f3423fc1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not ((5 != 6) or (4 < 100))" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "bccb03f4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True or True" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "05431594", + "metadata": {}, + "outputs": [], + "source": [ + "year = 1990\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "e20b919d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], + "source": [ + "year = 2025\n", + "\n", + "if year >= 2000:\n", + " print(\"We are in the 21st century.\")\n", + "else:\n", + " print(\"We are not in the 21st century.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "05c050a4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], + "source": [ + "year = 2025\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "elif year >= 1900:\n", + " print('We are in the 20th century.')\n", + "elif year >= 1800:\n", + " print('We are in the 19th century.')\n", + "else:\n", + " print('We have gone way back in time!')" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "b9ba8d69", + "metadata": {}, + "outputs": [], + "source": [ + "def eye_exam_covered(age, qualifying_condition, time_since_last_exam):\n", + " # age is int\n", + "\n", + " # qualifying_condition is a bool: True is you have an eligible\n", + " # medical condition, False is you do not\n", + "\n", + " # time_since_last_exam is int representing the months since your last exam\n", + "\n", + " if age <= 19:\n", + " if time_since_last_exam >= 12:\n", + " return \"You are eligible for 1 major eye exam and any minor assessments\"\n", + " else:\n", + " return \"You are eligible for minor assessments, but not a major eye exam.\"\n", + " \n", + " elif 20 <= age <= 64: \n", + " if qualifying_condition:\n", + " if time_since_last_exam >= 12:\n", + " return \"You are eligible for 1 major eye exam and 2 additional follow up minor assessments\"\n", + " else:\n", + " return \"It hasn't been 12 months since your last major eye exam.\"\n", + " else:\n", + " return \"You do not have an eligible medical condition affecting your eyes.\"\n", + " \n", + " elif age >= 65:\n", + " if time_since_last_exam >= 18:\n", + " return \"You are eligible for 1 major eye exam and 2 additional follow-up minor assessments\"\n", + " else:\n", + " return \"It hasn't been 18 months since your last major eye exam\"\n", + " \n", + " else:\n", + " return \"Invalid age input.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "3160470b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for 1 major eye exam and 2 additional follow-up minor assessments'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(67, True, 20)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "592bf5ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for 1 major eye exam and 2 additional follow up minor assessments'" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(27, True, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "cb353640", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for minor assessments, but not a major eye exam.'" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(19, False, 11)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "0bb21681", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels = ['a', 'e', 'i', 'o', 'u']\n", + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "b93df2aa", + "metadata": {}, + "outputs": [], + "source": [ + "empty_list = [] # conventional way\n", + "\n", + "empty_list2 = list()" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "1706ac14", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(empty_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "bfdc77fa", + "metadata": {}, + "outputs": [], + "source": [ + "scores = [90, 80, 82, 91, 80]\n", + "grades = ['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n", + "summary_functions = [len, sum, max, min]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1a43a7e9", + "metadata": {}, + "outputs": [], + "source": [ + "mystery_solvers = [['Sherlock', 'Watson'], \n", + " ['Scooby', 'Shaggy', 'Fred'], \n", + " 'Nancy']" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "40be8280", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "73c342cb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'K'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "442cbc38", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6, 7, 8]" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[6:9]" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "478374d5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[9, 10, 11, 12]" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[-4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "df0dbf67", + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[45], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mgrades\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m13\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mIndexError\u001b[0m: list index out of range" + ] + } + ], + "source": [ + "grades[13]" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "99217e5d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'dog' in 'examples of pets are dogs, cats, and birds'" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "3b4260a1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "926b9e8d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'y' in vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "58e82724", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "37" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares = [1, 4, 9, 16, 25, 37, 49]\n", + "\n", + "perfect_squares[5]" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "6209aed4", + "metadata": {}, + "outputs": [], + "source": [ + "perfect_squares[5] = 36" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "6e39b032", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "d8547186", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'cheese', 'bread']" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_sandwich = ['bread', 'cheese', 'bread']\n", + "julia_sandwich" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "a1fee9b3", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie_sandwich = julia_sandwich" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "407adedc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'cheese', 'bread']" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_sandwich" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "42c233d9", + "metadata": {}, + "outputs": [], + "source": [ + "julia_sandwich[1] = 'tomato'" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "d50a687b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'tomato', 'bread']" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_sandwich" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "7d0d687e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'tomato', 'bread']" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_sandwich" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20262ed3", + "metadata": {}, + "outputs": [], + "source": [ + "# ^^^ lists are mutable data types" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "357aa997", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_sandwich2 = 'cheese sandwich'\n", + "julia_sandwich2" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "6aa5cbc2", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie_sandwich2 = julia_sandwich2" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "0ba67a45", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_sandwich2" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "46f41187", + "metadata": {}, + "outputs": [], + "source": [ + "julia_sandwich2 = 'tomato sandwich'" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "0fe68d48", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tomato sandwich'" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_sandwich2" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "c81f7afc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie_sandwich2" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "7453d1c8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 1\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "0afaf657", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = a\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "251ca6b5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 2\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "ae3e5897", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "70ee88ab", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1, 2]\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "8ce0aeec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = a\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "f89a9902", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6, 2]" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a[0] = 6\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "84f772b6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6, 2]" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "28c33f2e", + "metadata": {}, + "outputs": [], + "source": [ + "combo = ['burger', 'fries', 'drink']\n", + "kid_meal = list(combo)" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "858104ee", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "combo" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "b118a24f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "9031f93d", + "metadata": {}, + "outputs": [], + "source": [ + "combo[0] = 'chicken sandwich'" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "44cdb53a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['chicken sandwich', 'fries', 'drink']" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "combo" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "6e1738ab", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "2dd30b0c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "aa4f3822", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "7fbc0e0e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "68220fb6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "49" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "1d19d501", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "da7925ed", + "metadata": {}, + "outputs": [], + "source": [ + "perfect_squares.append(64)" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "04c7a8a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49, 64]" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "299c554f", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}