From 6791f2a81cb0347f3247037ec60c56a62e12fc8d Mon Sep 17 00:00:00 2001 From: kaylielau Date: Thu, 27 Nov 2025 01:16:21 +0000 Subject: [PATCH] Update with live code --- 04_this_cohort/live-code/11_25_2025.ipynb | 1248 ++++++++++++++++++++ 04_this_cohort/live-code/11_26_2025.ipynb | 1310 ++++++++++++++------- 2 files changed, 2108 insertions(+), 450 deletions(-) create mode 100644 04_this_cohort/live-code/11_25_2025.ipynb diff --git a/04_this_cohort/live-code/11_25_2025.ipynb b/04_this_cohort/live-code/11_25_2025.ipynb new file mode 100644 index 000000000..104c8d415 --- /dev/null +++ b/04_this_cohort/live-code/11_25_2025.ipynb @@ -0,0 +1,1248 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "id": "c400ce4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "6d15bb20", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 + 0" + ] + }, + { + "cell_type": "markdown", + "id": "1b150756", + "metadata": {}, + "source": [ + " - `Shift + Enter`: Run the current cell and move to the next cell.\n", + " - `Ctrl + Enter`: Run the current cell and stay on the same cell.\n", + " - `Alt + Enter`: Run the current cell and insert a new cell below." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "c1d78b69", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello!\n" + ] + } + ], + "source": [ + "print(\"hello!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8839bafe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hi!\n" + ] + } + ], + "source": [ + "print(\"hi!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "3d38a859", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "goodbye!\n" + ] + } + ], + "source": [ + "print(\"goodbye!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "aa59179a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bye!\n" + ] + } + ], + "source": [ + "print(\"bye!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "89626de2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first live learning session!\n" + ] + } + ], + "source": [ + "print(\"first live learning session!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "af974aa1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# integers (int) are whole numbers\n", + "\n", + "5 + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a7c33a0f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# floating point (float) are decimal numbers\n", + "\n", + "5 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "760e7fb4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(5 / 2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85e4c937", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 // 3 # integer division (always rounding down)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f845bb1f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55812b4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 % 3 # modulo or remainder" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "69ab6c3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + }, + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(1 + 1)\n", + "10 ** 3 # exponentiation" + ] + }, + { + "cell_type": "markdown", + "id": "afec1d08", + "metadata": {}, + "source": [ + "| Operator | Description |\n", + "| --- | --- |\n", + "| `>` | Greater than |\n", + "| `>=` | Greater than or equal to |\n", + "| `<` | Less than |\n", + "| `<=` | Less than or equal to |\n", + "| `==` | Equal to |\n", + "| `!=` | Not equal to |" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "00af980c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "50 > 25" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "18068b17", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-15 >= - 14.99" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5072a136", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 == 20" + ] + }, + { + "cell_type": "markdown", + "id": "0a950f66", + "metadata": {}, + "source": [ + "| Order | Operator | Description |\n", + "|---|---|---|\n", + "| 1 | `**` | Exponentiation |\n", + "| 2 | `-`| Negation |\n", + "| 3 | `*`, `/`, `//`, `%` | Multiplication, division, integer division, and modulo |\n", + "| 4 | `+`, `-` | Addition and subtraction |\n", + "| 5 | `<`, `<=`, `>`, `>=`, `==`, `!=` | Less than, less than or equal to, greater than, greater than or equal to, equal, not equal |" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "c15ece65", + "metadata": {}, + "outputs": [], + "source": [ + "# can include digits, letters, and underscores\n", + "# cannot start with a digit\n", + "# are case sensitive\n", + "\n", + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "4a27a017", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "aa482540", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "440e601d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "0a5fa1ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(9 / 5) * 25 + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "93d1cc1b", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "f1e0083a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "c1030808", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "67cc65fc", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "2eb6ba2f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "9a51098f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "64ccfc66", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = degrees_celsius + 10 # 0 + 10" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "18660925", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "8049f1a3", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "698fe0ef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "23983056", + "metadata": {}, + "outputs": [], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "cf4f8c23", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "e92330f6", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "e1342150", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "c0c412ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25a1b50a", + "metadata": {}, + "outputs": [], + "source": [ + "# degrees_celsius = degrees_celsius + 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3bea5001", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-10" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = 0\n", + "degrees_celsius -= 10 # degrees_celsius = degrees_celsius - 10\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "0a753611", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "cannot assign to literal here. Maybe you meant '==' instead of '='? (3541004665.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[56]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m12 = x\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m cannot assign to literal here. Maybe you meant '==' instead of '='?\n" + ] + } + ], + "source": [ + "12 = x" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "2f1378eb", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (934255472.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[57]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m25 -\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], + "source": [ + "25 -" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "698e0c86", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'my_variable' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[58]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mmy_variable\u001b[49m + \u001b[32m1\u001b[39m\n", + "\u001b[31mNameError\u001b[39m: name 'my_variable' is not defined" + ] + } + ], + "source": [ + "my_variable + 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e52d6ccc", + "metadata": {}, + "outputs": [], + "source": [ + "# this is a comment!" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "2aabe068", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "600f5353", + "metadata": {}, + "outputs": [], + "source": [ + "no_cats = 60\n", + "no_dogs = 70\n", + "no_fish = 80\n", + "tot_animals = (no_cats \n", + " + no_dogs \n", + " + no_fish)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "f2734c5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "210" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tot_animals" + ] + }, + { + "cell_type": "markdown", + "id": "011aa018", + "metadata": {}, + "source": [ + "Version 1\n", + "```python\n", + "studentone_grade=90\n", + "StudentGrade2=50\n", + "stu3gr=74\n", + "avggrade=(studentone_grade+StudentGrade2+stut3gr)/3\n", + "```\n", + "\n", + "Version 2 \n", + "```python\n", + "student1_grade = 90\n", + "student2_grade = 50\n", + "student3_grade = 74\n", + "average_grade = ((student1_grade\n", + " + student2_grade\n", + " + student3_grade)\n", + " / 3)\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "0cb5f0e1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "it is Tuesday!\n" + ] + } + ], + "source": [ + "print(\"it is Tuesday!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "1a202f57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "58e2dda6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-43)" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "0c0a7950", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "c35bf94e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "55a50e3f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.99)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "bba25b06", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print(abs(round(-2 * 1.5)))" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "2323f93e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print(abs(round(-2 * 1.5)))" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "c3caa06a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on built-in function round in module builtins:\n", + "\n", + "round(number, ndigits=None)\n", + " Round a number to a given precision in decimal digits.\n", + " \n", + " The return value is an integer if ndigits is omitted or None. Otherwise\n", + " the return value has the same type as the number. ndigits may be negative.\n", + "\n" + ] + } + ], + "source": [ + "help(round)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "3105f39b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.556" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.5555555, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "544b046b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.5555555)" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "c276f64a", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " degrees_f = (9 / 5) * degrees_c + 32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "76d39831", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "fbadb263", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "c146ab87", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "302.0" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(150)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0f280034", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/04_this_cohort/live-code/11_26_2025.ipynb b/04_this_cohort/live-code/11_26_2025.ipynb index 104c8d415..0ce734303 100644 --- a/04_this_cohort/live-code/11_26_2025.ipynb +++ b/04_this_cohort/live-code/11_26_2025.ipynb @@ -2,324 +2,741 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, - "id": "c400ce4f", + "execution_count": 1, + "id": "d1b67a6e", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, divisor):\n", + " result = dividend / divisor\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b9ed9996", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2" + "0.0" ] }, - "execution_count": 4, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "1 + 1" + "divide(0, 2) # 0 is assigned to dividend, 2 assigned to divisor" ] }, { "cell_type": "code", - "execution_count": 5, - "id": "6d15bb20", + "execution_count": 3, + "id": "6008dcfc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3" + "2.0" ] }, - "execution_count": 5, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "3 + 0" + "divide(10, 5)" ] }, { - "cell_type": "markdown", - "id": "1b150756", + "cell_type": "code", + "execution_count": 4, + "id": "a0a298a1", "metadata": {}, + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mZeroDivisionError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# 2 dividend, 0 is divisor\u001b[39;00m\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 2\u001b[39m, in \u001b[36mdivide\u001b[39m\u001b[34m(dividend, divisor)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mdivide\u001b[39m(dividend, divisor):\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m result = \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mdivisor\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m result\n", + "\u001b[31mZeroDivisionError\u001b[39m: division by zero" + ] + } + ], "source": [ - " - `Shift + Enter`: Run the current cell and move to the next cell.\n", - " - `Ctrl + Enter`: Run the current cell and stay on the same cell.\n", - " - `Alt + Enter`: Run the current cell and insert a new cell below." + "divide(2, 0) # 2 dividend, 0 is divisor" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e094a835", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_sales_tax(price, tax_rate=0.13):\n", + " sales_tax = price * tax_rate\n", + " return sales_tax" ] }, { "cell_type": "code", "execution_count": 6, - "id": "c1d78b69", + "id": "5dd1331e", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello!\n" - ] + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print(\"hello!\")" + "calc_sales_tax(5)" ] }, { "cell_type": "code", "execution_count": 7, - "id": "8839bafe", + "id": "fc9af608", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "hi!\n" - ] + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print(\"hi!\")" + "5 * 0.13" ] }, { "cell_type": "code", "execution_count": 8, - "id": "3d38a859", + "id": "30192b08", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5, 0.08)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "43955897", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 * 0.08" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "e02f2485", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "27a99a7f", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate=0.13, tip_rate=0.15):\n", + " '''Calculate total bill with tax and tip.'''\n", + " tax = price * tax_rate\n", + " tip = price * tip_rate\n", + " total = price + tax + tip\n", + " return total" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "35e9a8e3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "256.0" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(200)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "016a0a7e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "266.0" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(200, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "b9a2a626", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "262.0" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(200, tip_rate=0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "5fd548aa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "goodbye!\n" + "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": [ - "print(\"goodbye!\")" + "help(round)" ] }, { "cell_type": "code", - "execution_count": 9, - "id": "aa59179a", + "execution_count": 16, + "id": "9528569b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "bye!\n" + "Help on function calc_total_bill in module __main__:\n", + "\n", + "calc_total_bill(price, tax_rate=0.13, tip_rate=0.15)\n", + " Calculate total bill with tax and tip.\n", + "\n" ] } ], "source": [ - "print(\"bye!\")" + "help(calc_total_bill)" ] }, { "cell_type": "code", - "execution_count": 10, - "id": "89626de2", + "execution_count": 17, + "id": "42ad1081", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "first live learning session!\n" + "Help on function calc_total_bill in module __main__:\n", + "\n", + "calc_total_bill(price, tax_rate=0.13, tip_rate=0.15)\n", + " Calculate total bill with tax and tip.\n", + "\n" ] } ], "source": [ - "print(\"first live learning session!\")" + "help(calc_total_bill)" ] }, { "cell_type": "code", - "execution_count": 11, - "id": "af974aa1", + "execution_count": 18, + "id": "e23b51ce", + "metadata": {}, + "outputs": [], + "source": [ + "x = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "301f444e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "11" + "10" ] }, - "execution_count": 11, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# integers (int) are whole numbers\n", - "\n", - "5 + 6" + "x" ] }, { "cell_type": "code", - "execution_count": 12, - "id": "a7c33a0f", + "execution_count": 20, + "id": "7b70a7ab", + "metadata": {}, + "outputs": [], + "source": [ + "output = 60" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "95da6d0b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2.5" + "60" ] }, - "execution_count": 12, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# floating point (float) are decimal numbers\n", - "\n", - "5 / 2" + "output" ] }, { "cell_type": "code", - "execution_count": 14, - "id": "760e7fb4", + "execution_count": 22, + "id": "d2ef0d2c", + "metadata": {}, + "outputs": [], + "source": [ + "favourite_food = \"mashed potatoes\"" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "7f5e6691", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "float" + "'mashed potatoes'" ] }, - "execution_count": 14, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "type(5 / 2)" + "favourite_food" ] }, { "cell_type": "code", - "execution_count": null, - "id": "85e4c937", + "execution_count": 24, + "id": "20d721a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3" + "'mashed potatoes'" ] }, - "execution_count": 15, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "10 // 3 # integer division (always rounding down)" + "'mashed potatoes'" ] }, { "cell_type": "code", - "execution_count": 16, - "id": "f845bb1f", + "execution_count": 25, + "id": "24d572a1", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unterminated string literal (detected at line 1) (3453317070.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[25]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m\"mashed potatoes'\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m unterminated string literal (detected at line 1)\n" + ] + } + ], + "source": [ + "\"mashed potatoes'" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "2d4a1339", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (1618629434.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[26]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m'Let's see if this works\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], + "source": [ + "'Let's see if this works" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "16cbd2fc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3.3333333333333335" + "\"Let's see if this works\"" ] }, - "execution_count": 16, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "10 / 3" + "\"Let's see if this works\"" ] }, { "cell_type": "code", - "execution_count": null, - "id": "55812b4f", + "execution_count": 29, + "id": "3ee22827", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "'I am a multiline string\\n\\nI span over many\\nmany\\nmany\\nlines \\nof \\ncode\\n'" ] }, - "execution_count": 17, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "10 % 3 # modulo or remainder" + "\"\"\"I am a multiline string\n", + "\n", + "I span over many\n", + "many\n", + "many\n", + "lines \n", + "of \n", + "code\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "id": "4b971f42", + "metadata": {}, + "source": [ + "| Escape sequence | Description |\n", + "|-----------------|--------------------|\n", + "| \\\\' | Single quote |\n", + "| \\\\\" | Double quote |\n", + "| \\\\\\\\ | Backslash |\n", + "| \\\\t | Tab |\n", + "| \\\\n | Newline |" ] }, { "cell_type": "code", - "execution_count": 21, - "id": "69ab6c3a", + "execution_count": 45, + "id": "328dbdc4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is \ta tab\n" + ] + } + ], + "source": [ + "print(\"This is \\ta tab\")" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "dcb75bc0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2\n" + "This is\n", + "a newline\n" ] - }, + } + ], + "source": [ + "print(\"This is\\na newline\")" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "ae11bf47", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is \\ a backslash\n" + ] + } + ], + "source": [ + "print(\"This is \\\\ a backslash\")" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "164ca528", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is \" a double quote\n" + ] + } + ], + "source": [ + "print(\"This is \\\" a double quote\")" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "a86d2ce8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Xindi said \"hi!\"\n" + ] + } + ], + "source": [ + "print(\"Xindi said \\\"hi!\\\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "b20e4404", + "metadata": {}, + "outputs": [ { "data": { "text/plain": [ - "1000" + "2" ] }, - "execution_count": 21, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "print(1 + 1)\n", - "10 ** 3 # exponentiation" + "1 + 1" ] }, { - "cell_type": "markdown", - "id": "afec1d08", + "cell_type": "code", + "execution_count": 54, + "id": "1264e1d1", "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello world'" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "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 |" + "'hello' + ' world'" ] }, { "cell_type": "code", - "execution_count": 22, - "id": "00af980c", + "execution_count": 55, + "id": "c69b309c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hahaha'" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'ha' * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "99da7f84", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"int\") to str", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[56]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[33;43m'\u001b[39;49m\u001b[33;43mhello\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2020\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "'hello' + 2020" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "0525f823", "metadata": {}, "outputs": [ { @@ -328,19 +745,19 @@ "True" ] }, - "execution_count": 22, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "50 > 25" + "20 == 20" ] }, { "cell_type": "code", - "execution_count": 23, - "id": "18068b17", + "execution_count": 57, + "id": "f209b780", "metadata": {}, "outputs": [ { @@ -349,19 +766,19 @@ "False" ] }, - "execution_count": 23, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "-15 >= - 14.99" + "'apple' == 'Apple'" ] }, { "cell_type": "code", - "execution_count": 26, - "id": "5072a136", + "execution_count": 58, + "id": "377ebc5a", "metadata": {}, "outputs": [ { @@ -370,855 +787,848 @@ "True" ] }, - "execution_count": 26, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "20 == 20" + "'apple' != 'Apple'" ] }, { - "cell_type": "markdown", - "id": "0a950f66", + "cell_type": "code", + "execution_count": 60, + "id": "1bacd0f8", "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "| Order | Operator | Description |\n", - "|---|---|---|\n", - "| 1 | `**` | Exponentiation |\n", - "| 2 | `-`| Negation |\n", - "| 3 | `*`, `/`, `//`, `%` | Multiplication, division, integer division, and modulo |\n", - "| 4 | `+`, `-` | Addition and subtraction |\n", - "| 5 | `<`, `<=`, `>`, `>=`, `==`, `!=` | Less than, less than or equal to, greater than, greater than or equal to, equal, not equal |" + "'20' == 20" ] }, { "cell_type": "code", - "execution_count": 34, - "id": "c15ece65", + "execution_count": 61, + "id": "f63046a9", "metadata": {}, "outputs": [], "source": [ - "# can include digits, letters, and underscores\n", - "# cannot start with a digit\n", - "# are case sensitive\n", - "\n", - "degrees_celsius = 25" + "first_name = 'Ada'\n", + "last_name = 'Lovelace'" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "d8e84dd5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "280427eb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'c'" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[6]" ] }, { "cell_type": "code", - "execution_count": 35, - "id": "4a27a017", + "execution_count": 66, + "id": "a1d5a5e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "25" + "'ovel'" ] }, - "execution_count": 35, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_celsius" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "id": "aa482540", - "metadata": {}, - "outputs": [], - "source": [ - "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + "last_name[1:5]" ] }, { "cell_type": "code", - "execution_count": 37, - "id": "440e601d", + "execution_count": 67, + "id": "50f0f800", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "77.0" + "'el'" ] }, - "execution_count": 37, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_fahrenheit" + "last_name[3:5]" ] }, { "cell_type": "code", - "execution_count": 38, - "id": "0a5fa1ec", + "execution_count": 68, + "id": "39ee356c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "77.0" + "'Lovela'" ] }, - "execution_count": 38, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "(9 / 5) * 25 + 32" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "id": "93d1cc1b", - "metadata": {}, - "outputs": [], - "source": [ - "degrees_celsius = 0" + "last_name[0:6]" ] }, { "cell_type": "code", - "execution_count": 40, - "id": "f1e0083a", + "execution_count": 69, + "id": "3fda0ba1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0" + "'Lovela'" ] }, - "execution_count": 40, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_celsius" + "last_name[:6]" ] }, { "cell_type": "code", - "execution_count": 41, - "id": "c1030808", + "execution_count": 70, + "id": "cd302d0e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "77.0" + "'elace'" ] }, - "execution_count": 41, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_fahrenheit" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "id": "67cc65fc", - "metadata": {}, - "outputs": [], - "source": [ - "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + "last_name[3:]" ] }, { "cell_type": "code", - "execution_count": 43, - "id": "2eb6ba2f", + "execution_count": 71, + "id": "27774098", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "32.0" + "'Lovelace'" ] }, - "execution_count": 43, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_fahrenheit" + "last_name[:]" ] }, { "cell_type": "code", - "execution_count": 44, - "id": "9a51098f", + "execution_count": 77, + "id": "c39b7a1b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0" + "'ac'" ] }, - "execution_count": 44, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_celsius" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "64ccfc66", - "metadata": {}, - "outputs": [], - "source": [ - "degrees_celsius = degrees_celsius + 10 # 0 + 10" + "last_name[-3:-1]" ] }, { "cell_type": "code", - "execution_count": 46, - "id": "18660925", + "execution_count": 78, + "id": "69456f63", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "10" + "'oea'" ] }, - "execution_count": 46, + "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_celsius" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "id": "8049f1a3", - "metadata": {}, - "outputs": [], - "source": [ - "a = 1" + "last_name[1:6:2]" ] }, { "cell_type": "code", - "execution_count": 48, - "id": "698fe0ef", + "execution_count": 79, + "id": "4beff2e0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "'ecal'" ] }, - "execution_count": 48, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a" + "last_name[-1:-5:-1]" ] }, { "cell_type": "code", - "execution_count": 49, - "id": "23983056", + "execution_count": 81, + "id": "32eee259", "metadata": {}, "outputs": [], "source": [ - "b = a" + "phone_number = '+1 555-123-4567'" ] }, { "cell_type": "code", - "execution_count": 50, - "id": "cf4f8c23", + "execution_count": 82, + "id": "1f230cad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "'555'" ] }, - "execution_count": 50, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b" + "phone_number[3:6]" ] }, { "cell_type": "code", - "execution_count": 51, - "id": "e92330f6", + "execution_count": 83, + "id": "afb02ece", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 fish 2 fish\n" + ] + } + ], "source": [ - "a = 2" + "print(1, \"fish\", 2, \"fish\")" ] }, { "cell_type": "code", - "execution_count": 52, - "id": "e1342150", + "execution_count": 84, + "id": "108fdc8c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2" + "30" ] }, - "execution_count": 52, + "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a" + "len(\"gnaldkfgjalfnklasmkflmaklsmlak\")" ] }, { "cell_type": "code", - "execution_count": 53, - "id": "c0c412ae", + "execution_count": 86, + "id": "420fe4db", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "['a', 'a', 'a', 'b', 'n', 'n']" ] }, - "execution_count": 53, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "25a1b50a", - "metadata": {}, - "outputs": [], - "source": [ - "# degrees_celsius = degrees_celsius + 10" + "sorted(\"banana\")" ] }, { "cell_type": "code", - "execution_count": null, - "id": "3bea5001", + "execution_count": 87, + "id": "11026d64", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "-10" + "'I AM NOT YELLING'" ] }, - "execution_count": 55, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "degrees_celsius = 0\n", - "degrees_celsius -= 10 # degrees_celsius = degrees_celsius - 10\n", - "degrees_celsius" + "'I am not yelling'.upper()" ] }, { "cell_type": "code", - "execution_count": 56, - "id": "0a753611", + "execution_count": 88, + "id": "6e9ddc72", "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "cannot assign to literal here. Maybe you meant '==' instead of '='? (3541004665.py, line 1)", - "output_type": "error", - "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[56]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m12 = x\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m cannot assign to literal here. Maybe you meant '==' instead of '='?\n" - ] + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "12 = x" + "'This string is unusual'.count('e')" ] }, { "cell_type": "code", - "execution_count": 57, - "id": "2f1378eb", + "execution_count": 90, + "id": "01d48e31", "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (934255472.py, line 1)", - "output_type": "error", - "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[57]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m25 -\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" - ] + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "25 -" + "'file_name.xlsx'.endswith('.csv')" ] }, { "cell_type": "code", - "execution_count": 58, - "id": "698e0c86", + "execution_count": 91, + "id": "d4cdac65", "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'my_variable' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", - "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[58]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mmy_variable\u001b[49m + \u001b[32m1\u001b[39m\n", - "\u001b[31mNameError\u001b[39m: name 'my_variable' is not defined" - ] + "data": { + "text/plain": [ + "'long_file_name_with_spaces.csv'" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "my_variable + 1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e52d6ccc", - "metadata": {}, - "outputs": [], - "source": [ - "# this is a comment!" + "'long file name with spaces.csv'.replace(' ', '_')" ] }, { "cell_type": "code", - "execution_count": 59, - "id": "2aabe068", + "execution_count": 92, + "id": "0b7e21de", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2.5" + "'Ada'" ] }, - "execution_count": 59, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "5 / 2" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "id": "600f5353", - "metadata": {}, - "outputs": [], - "source": [ - "no_cats = 60\n", - "no_dogs = 70\n", - "no_fish = 80\n", - "tot_animals = (no_cats \n", - " + no_dogs \n", - " + no_fish)" + "first_name" ] }, { "cell_type": "code", - "execution_count": 63, - "id": "f2734c5f", + "execution_count": 93, + "id": "333db6a8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "210" + "'Lovelace'" ] }, - "execution_count": 63, + "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "tot_animals" - ] - }, - { - "cell_type": "markdown", - "id": "011aa018", - "metadata": {}, - "source": [ - "Version 1\n", - "```python\n", - "studentone_grade=90\n", - "StudentGrade2=50\n", - "stu3gr=74\n", - "avggrade=(studentone_grade+StudentGrade2+stut3gr)/3\n", - "```\n", - "\n", - "Version 2 \n", - "```python\n", - "student1_grade = 90\n", - "student2_grade = 50\n", - "student3_grade = 74\n", - "average_grade = ((student1_grade\n", - " + student2_grade\n", - " + student3_grade)\n", - " / 3)\n", - "```" + "last_name" ] }, { "cell_type": "code", - "execution_count": 64, - "id": "0cb5f0e1", + "execution_count": null, + "id": "5f2d285a", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "it is Tuesday!\n" - ] + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print(\"it is Tuesday!\")" + "# formatting strings\n", + "\n", + "# .format() string method\n", + "\n", + "'Ada Lovelace\\'s initials are {}. {}.'.format(first_name[0], last_name[0])" ] }, { "cell_type": "code", - "execution_count": 65, - "id": "1a202f57", + "execution_count": 99, + "id": "9d0ddd91", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "int" + "'My favourite day of the week is Wednesday.'" ] }, - "execution_count": 65, + "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "type(42)" + "day_of_week = 'Wednesday'\n", + "\n", + "'My favourite day of the week is {}.'.format(day_of_week)" ] }, { "cell_type": "code", - "execution_count": 66, - "id": "58e2dda6", + "execution_count": 102, + "id": "32a8142a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "43" + "\"Ada Lovelace's initials are A. L.\"" ] }, - "execution_count": 66, + "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "abs(-43)" + "# f-string\n", + "\n", + "f'Ada Lovelace\\'s initials are {first_name[0]}. {last_name[0]}.'" ] }, { "cell_type": "code", - "execution_count": 67, - "id": "0c0a7950", + "execution_count": 104, + "id": "12d67c95", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "'My favourite sport is skiing'" ] }, - "execution_count": 67, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "round(2/3)" + "favourite_sport = 'skiing'\n", + "\n", + "f'My favourite sport is {favourite_sport}'" ] }, { "cell_type": "code", - "execution_count": 68, - "id": "c35bf94e", + "execution_count": null, + "id": "5ad664fe", + "metadata": {}, + "outputs": [], + "source": [ + "# String to integer" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "9e5abfb3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.6666666666666666" + "int" ] }, - "execution_count": 68, + "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "2 / 3" + "type(int('17'))" ] }, { "cell_type": "code", - "execution_count": 69, - "id": "55a50e3f", + "execution_count": 107, + "id": "6cdeae6b", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 69, - "metadata": {}, - "output_type": "execute_result" + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: '17.4'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[107]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43m17.4\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: '17.4'" + ] } ], "source": [ - "int(3.99)" + "int('17.4')" ] }, { "cell_type": "code", - "execution_count": 70, - "id": "bba25b06", + "execution_count": 108, + "id": "1793ab2e", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: 'me'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[108]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mme\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: 'me'" ] } ], "source": [ - "print(abs(round(-2 * 1.5)))" + "int('me')" ] }, { "cell_type": "code", - "execution_count": 74, - "id": "2323f93e", + "execution_count": 109, + "id": "d4968579", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] + "data": { + "text/plain": [ + "892.0" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print(abs(round(-2 * 1.5)))" + "# String to float\n", + "\n", + "float('892')" ] }, { "cell_type": "code", - "execution_count": 75, - "id": "c3caa06a", + "execution_count": 110, + "id": "5cbd826d", "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" + "ename": "ValueError", + "evalue": "could not convert string to float: 'you'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[110]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43myou\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[31mValueError\u001b[39m: could not convert string to float: 'you'" ] } ], "source": [ - "help(round)" + "float('you')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2160942", + "metadata": {}, + "outputs": [], + "source": [ + "# float and int to string" ] }, { "cell_type": "code", - "execution_count": 76, - "id": "3105f39b", + "execution_count": 111, + "id": "b87269bc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3.556" + "'37.5'" ] }, - "execution_count": 76, + "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "round(3.5555555, 3)" + "str(37.5)" ] }, { "cell_type": "code", - "execution_count": 77, - "id": "544b046b", + "execution_count": 112, + "id": "d1827a26", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "4" + "'20'" ] }, - "execution_count": 77, + "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "round(3.5555555)" - ] - }, - { - "cell_type": "code", - "execution_count": 92, - "id": "c276f64a", - "metadata": {}, - "outputs": [], - "source": [ - "def c_to_f(degrees_c):\n", - " degrees_f = (9 / 5) * degrees_c + 32\n", - " return degrees_f" + "str(20)" ] }, { "cell_type": "code", - "execution_count": 93, - "id": "76d39831", + "execution_count": 113, + "id": "688f54ba", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "212.0" + "'2037.5'" ] }, - "execution_count": 93, + "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "c_to_f(100)" + "'20' + str(37.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "4a742c18", + "metadata": {}, + "outputs": [], + "source": [ + "age = input('How old are you? ')" ] }, { "cell_type": "code", - "execution_count": 95, - "id": "fbadb263", + "execution_count": 123, + "id": "73bb1923", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "12.2" + "'1000'" ] }, - "execution_count": 95, + "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "c_to_f(-11)" + "age" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "c3b0b135", + "metadata": {}, + "outputs": [], + "source": [ + "age_next_bday = int(age) + 1" ] }, { "cell_type": "code", - "execution_count": 96, - "id": "c146ab87", + "execution_count": 125, + "id": "e20f5ced", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "302.0" + "1001" ] }, - "execution_count": 96, + "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "c_to_f(150)" + "age_next_bday" ] }, { "cell_type": "code", "execution_count": null, - "id": "0f280034", + "id": "0b9d88e5", "metadata": {}, "outputs": [], "source": []