From db780743833435e460f6cb49a9396044081e4e84 Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Sat, 18 Apr 2026 21:39:36 -0400 Subject: [PATCH 1/4] Save progress on anagram checker before pulling --- 02_activities/assignments/assignment_1.ipynb | 102 +++++++++++++++---- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 2dca19d0b..c96587e50 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -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", + " #the function should return True if the words are anagrams and False if they are not\n", + " return sorted(word_a.lower()) == sorted(word_b.lower())\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,31 +130,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", - "\n", + "# This function returns True if the words are anagrams and False if they are not. The function also takes into account whether the anagram check should be case sensitive or not based on the value of is_case_sensitive.\n", + " return sorted(word_a) == sorted(word_b) if is_case_sensitive else sorted(word_a.lower()) == sorted(word_b.lower())\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"listen\", True) # False" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -139,7 +205,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -153,7 +219,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.15" } }, "nbformat": 4, From 834b2ab8258ef1315552ae70aafe5f374bedba5b Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Sat, 18 Apr 2026 21:45:00 -0400 Subject: [PATCH 2/4] Save local live-code notebooks before pulling --- .../live-code/live_code-04-14-26.ipynb | 1430 +++++++++++ .../live-code/live_code-04-15-26.ipynb | 1792 +++++++++++++ .../live-code/live_code-04-16-26.ipynb | 2240 +++++++++++++++++ 3 files changed, 5462 insertions(+) create mode 100644 04_this_cohort/live-code/live_code-04-14-26.ipynb create mode 100644 04_this_cohort/live-code/live_code-04-15-26.ipynb create mode 100644 04_this_cohort/live-code/live_code-04-16-26.ipynb diff --git a/04_this_cohort/live-code/live_code-04-14-26.ipynb b/04_this_cohort/live-code/live_code-04-14-26.ipynb new file mode 100644 index 000000000..60732be14 --- /dev/null +++ b/04_this_cohort/live-code/live_code-04-14-26.ipynb @@ -0,0 +1,1430 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 77, + "id": "2b2ac9bb", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "25bc23cc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "markdown", + "id": "a5878f06", + "metadata": {}, + "source": [ + "### This code adds *one plus one*" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "80d2a942", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 ** 3" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "79da5b66", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "cc3fd6fe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "c7445449", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 // 3" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "97ec35f5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 > 3" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "9efebf12", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 < 3" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "b16fa866", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 == 3" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "098a3de8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 != 3" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "f57d7cdb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "26" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(10 + 3) * 2" + ] + }, + { + "cell_type": "markdown", + "id": "2413a660", + "metadata": {}, + "source": [ + "1. variable name cannot begin with a number\n", + "2. can only be letters, numbers and underscores \n", + "3. case sensitive" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "ac7b0002", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "86c1923d", + "metadata": {}, + "outputs": [], + "source": [ + "deegreesCelsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "ed0b57ed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "cab877b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius != 25" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "7c3ca40f", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9/5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "0be41e9f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "4f569cd8", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 35" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "d9fe7800", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "45" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius = degrees_celsius + 10\n", + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "7326c32e", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius += 10" + ] + }, + { + "cell_type": "markdown", + "id": "cbd9c8fc", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "10ddd1f8", + "metadata": {}, + "outputs": [], + "source": [ + "name = \"Cezar\"\n", + "age = 38\n", + "favourite_number = 7" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "81cb4438", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Cezar'" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "c5525244", + "metadata": {}, + "outputs": [], + "source": [ + "age -= 10" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "b1796d3c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "28\n", + "Cezar\n", + "7\n" + ] + } + ], + "source": [ + "print(age)\n", + "print(name)\n", + "print(favourite_number)" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "08418246", + "metadata": {}, + "outputs": [], + "source": [ + "# This is a comment. it will not be evaluated by Python" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "f0fb90ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "71.33333333333333" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student1_grade = 90\n", + "student2_grade = 50\n", + "student3_grade = 74\n", + "\n", + "average_grade = (student1_grade + student2_grade + student3_grade) / 3\n", + "average_grade # This is the average of 3 students grades" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "d88aa7a6", + "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[103]\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": null, + "id": "3c666aba", + "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[49]\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": "markdown", + "id": "b353568d", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5ac0c2f", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'mean' 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[50]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[32m 2\u001b[39m numbers = [\u001b[32m10\u001b[39m,\u001b[32m20\u001b[39m,\u001b[32m30\u001b[39m]\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m#This is what is giving me the error:\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m \u001b[43mmean\u001b[49m(numbers)\n", + "\u001b[31mNameError\u001b[39m: name 'mean' is not defined" + ] + } + ], + "source": [ + "#Trying to get the average of a list\n", + "numbers = [10,20,30]\n", + "\n", + "#This is what is giving me the error:\n", + "mean(numbers)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "624dfc38", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], + "source": [ + "#1. Name error\n", + "total = 80\n", + "print(total)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8081e383", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#2. Syntax error\n", + "number3 = 10\n", + "number3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ae4a43ef", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "print(42)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26b08ce1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100\n" + ] + } + ], + "source": [ + "print(10**2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8a032a18", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "42" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-42)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6afa165", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.7)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afb8f49f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.14" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3.14159,2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55f0b47c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.7)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "58ddffc7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5.0" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d082d403", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "print(abs(round(-2*1.75)))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79ba7aac", + "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": null, + "id": "88ce4cdc", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_celsius):\n", + " #convert degrees from celsius to fahrenheit\n", + " return (degrees_celsius * (9/5)) + 32" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82f91a07", + "metadata": {}, + "outputs": [], + "source": [ + "freezing_point_f = c_to_f(0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a52c5a73", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f64820e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freezing_point_f" + ] + }, + { + "cell_type": "markdown", + "id": "d090da8e", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "97e0a92e", + "metadata": {}, + "outputs": [], + "source": [ + "def f_to_c(degrees_fahrenheit):\n", + " #This function is going to convert degrees Fahrenheit to celcius\n", + " return (degrees_fahrenheit - 32) * 5/9" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4fb02544", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f_to_c(32)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "804f8d5b", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, divisor):\n", + " return dividend / divisor" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa0e4817", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(0,2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "08d134c9", + "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[73]\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[32;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[71]\u001b[39m\u001b[32m, line 2\u001b[39m, in \u001b[36mdivide\u001b[39m\u001b[34m(dividend, divisor)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mdivide\u001b[39m(dividend, divisor):\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mdivisor\u001b[49m\n", + "\u001b[31mZeroDivisionError\u001b[39m: division by zero" + ] + } + ], + "source": [ + "divide(2,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "e6ef2ed0", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_sale_tax(price, tax_rate = 0.13):\n", + " return price * tax_rate" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "f6e260aa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.0" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sale_tax(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "be49771d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5.0" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sale_tax(100,.05)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "2ed56f56", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate = 0.13, tip_rate = 0.2):\n", + " tax = price * tax_rate\n", + " tip = price * tip_rate\n", + " return price + tax + tip" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "2c8cb519", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "a3f099f7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "135.0" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(price = 100, tip_rate=0.22)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "56ceef1d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "142.0" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, 0.22)" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "0c9d464c", + "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": 110, + "id": "7215466c", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_celsius):\n", + " \"\"\"\n", + " Converts a temperature from Celsius to Fahrenheit.\n", + "\n", + " Parameters:\n", + " degrees_celsius (float): Temperature in degrees celsius.\n", + "\n", + " Returns:\n", + " float: Temperature in degrees fahrenheit.\n", + " \"\"\"\n", + "\n", + " return (degrees_celsius * (9/5)) + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "id": "5f37ac44", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function c_to_f in module __main__:\n", + "\n", + "c_to_f(degrees_celsius)\n", + " Converts a temperature from Celsius to Fahrenheit.\n", + " \n", + " Parameters:\n", + " degrees_celsius (float): Temperature in degrees celsius.\n", + " \n", + " Returns:\n", + " float: Temperature in degrees fahrenheit.\n", + "\n" + ] + } + ], + "source": [ + "help(c_to_f)" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "793319c6", + "metadata": {}, + "outputs": [], + "source": [ + "def example():\n", + " local_var = 10\n", + " return local_var" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "id": "d1a6194b", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'local_var' 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[113]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mlocal_var\u001b[49m\n", + "\u001b[31mNameError\u001b[39m: name 'local_var' is not defined" + ] + } + ], + "source": [ + "local_var" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "8ea04e36", + "metadata": {}, + "outputs": [], + "source": [ + "global_var = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "1287c6d4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "global_var" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "782ca441", + "metadata": {}, + "outputs": [], + "source": [ + "def example():\n", + " return global_var" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "id": "28e4c677", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "example()" + ] + }, + { + "cell_type": "markdown", + "id": "ac3e74b6", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "id": "9a551b99", + "metadata": {}, + "outputs": [], + "source": [ + "def count_letters(word):\n", + " \"\"\"\n", + " This function take in a string, and return the number of characters in that string.\n", + "\n", + " For example, count_letters(\"hello\") would return 5.\n", + " \"\"\"\n", + " return len(word)" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "id": "a7b3cd57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "count_letters(\"julia\")" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "db2ca904", + "metadata": {}, + "outputs": [], + "source": [ + "def rectangle_volume(length, width, height):\n", + " \"\"\"\n", + " This function will calculate the volume of a rectangle when given a length, width and height.\n", + " \"\"\"\n", + " return length * width * height" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "id": "63f2335b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "500" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rectangle_volume(10,10,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "066935ad", + "metadata": {}, + "outputs": [], + "source": [ + "conversion_rate = 0.73" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "id": "ed79c0e0", + "metadata": {}, + "outputs": [], + "source": [ + "def can_to_us(can):\n", + " \"\"\"\n", + " Convert canadian dollars to USD.\n", + " Parameters:\n", + " can(float): Amount in CAD\n", + " Returns:\n", + " float: Amount in USD\n", + " \"\"\"\n", + " return can * conversion_rate" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "id": "2a516f3c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7.3" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "can_to_us(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "590d6079", + "metadata": {}, + "outputs": [], + "source": [ + "def greet():\n", + " return(\"Hello!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "id": "b63b9fc4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello!'" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greet()" + ] + } + ], + "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/live_code-04-15-26.ipynb b/04_this_cohort/live-code/live_code-04-15-26.ipynb new file mode 100644 index 000000000..a435843b1 --- /dev/null +++ b/04_this_cohort/live-code/live_code-04-15-26.ipynb @@ -0,0 +1,1792 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "1197c13d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'this is a string'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"this is a string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "48e9f33d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'so is this'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'so is this'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "004f4d55", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unterminated string literal (detected at line 1) (4209509764.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m\"these quotes dont match!'\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m unterminated string literal (detected at line 1)\n" + ] + } + ], + "source": [ + "\"these quotes dont match!'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "12b79ada", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Let's using double quotes to avoid error\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Let's using double quotes to avoid error\"" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "dc5054ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nThis is a \\nmultiline string\\nin python\\n'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "This is a \n", + "multiline string\n", + "in python\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "173d9239", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello\n", + "World\n" + ] + } + ], + "source": [ + "print(\"Hello\\nWorld\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "d14ff5a4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"It's\"" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'It\\'s'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "d8f7f2d8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: \t Alice\n" + ] + } + ], + "source": [ + "print(\"Name: \\t Alice\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "9569a519", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello World'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Hello\" + \" World\"" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "99943125", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "1e500584", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hahaha'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"ha\" * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "54868029", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "7fc21a27", + "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[13]\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;43mThe year is\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2026\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "\"The year is\" + 2026" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f351571e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 == 1" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "559d7111", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"apple\" == \"Apple\"" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "bfb0d170", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"apple\" != \"Apple\"" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "c657c362", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"20\" == 20" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "e25fdeb2", + "metadata": {}, + "outputs": [], + "source": [ + "name = \"Alice\"" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "3b2d04ca", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'A'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "2959844b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ali'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name[0:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "9df4f9ad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'e'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "d7ee3ebc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ice'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name[-3:]" + ] + }, + { + "cell_type": "markdown", + "id": "0a65a5c8", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "aadf52ce", + "metadata": {}, + "outputs": [], + "source": [ + "word = \"supercalifragilisticexpialidocious\"" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "89e329db", + "metadata": {}, + "outputs": [], + "source": [ + "number = \"(647)-225-7154\"" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "6d3b3c10", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'superc'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word[0:6]" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "0c7c539a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'647'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "number[1:4]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "b3c05c33", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "job_qualifications = \"The successful applicant will be proficient in R, Python, SQL, statistics, and data visualization\"\n", + "\n", + "\"R\" in job_qualifications" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "3563d369", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"R\" in job_qualifications" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "04e17828", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(\"Sometimes we type long-winded sentences to meet word counts or character counts.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "df7d95b9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(name)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "4dc1c6a6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLING'" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#convert a string to upper case\n", + "\n", + "\"I am not yelling\".upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "cff1615e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'i am not yelling'" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"I AM NOT YELLING\".lower()" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "12fd290a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"This string is unusual\".count(\"s\")" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "8b54654f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"file_name.csv\".endswith(\".csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "e2da9891", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'file-name'" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"file name\".replace(\" \",\"-\")" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "5b49d69c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method_descriptor:\n", + "\n", + "lower(self, /) unbound builtins.str method\n", + " Return a copy of the string converted to lowercase.\n", + "\n" + ] + } + ], + "source": [ + "help(str.lower)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "6d846319", + "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[43]\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;43mMy age is\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m26\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "\"My age is\" + 26" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "ab62a467", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Initials are A. L'" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name = \"Ada\"\n", + "last_name = \"Lovelace\"\n", + "\n", + "\"Initials are {}. {}\".format(first_name[0],last_name[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "c0a250ef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Initials are A. L'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f\"Initials are {first_name[0]}. {last_name[0]}\"" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "a5e8e841", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "17" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int('17')" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "914c8cdb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "17.0" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float('17')" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "f8d98721", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'37.5'" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(37.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "2b522101", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'2037.5'" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'20' + str(37.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "8e224f35", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "57.5" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float('20') + 37.5" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "89c9d39f", + "metadata": {}, + "outputs": [ + { + "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[52]\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": [ + "int('me')" + ] + }, + { + "cell_type": "markdown", + "id": "9d6a9262", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "7a8229fa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The year is 2026'" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"The year is \" + str(2026)" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "0e3c75b9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The year is 2026.'" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f\"The year is {2026}.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "ce60e762", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The year is 2026'" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"The year is {}\".format(2026)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "d8343b81", + "metadata": {}, + "outputs": [], + "source": [ + "age = input(\"How old are you?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "0f21b6a6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'28'" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "cbbf33d5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "29" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(age) + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "ec6e89bb", + "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[61]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mage\u001b[49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m1\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "age + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "088b385c", + "metadata": {}, + "outputs": [], + "source": [ + "def greet_user():\n", + " name = input(\"Enter your name\")\n", + " return(f\"Hello,{name}!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "28cdadd0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello,Julia!'" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greet_user()" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "47256151", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n" + ] + } + ], + "source": [ + "num = int(input(\"Enter a number:\"))\n", + "print(num + 1)" + ] + }, + { + "cell_type": "markdown", + "id": "858fb9f9", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "4d8b3d12", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Users favourite color is: blue'" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Exercise 1\n", + "col = input(\"What is your favourite color?\")\n", + "\n", + "f\"Users favourite color is: {col}\"" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "e23b45b7", + "metadata": {}, + "outputs": [], + "source": [ + "#Exercise 2\n", + "\n", + "def full_name():\n", + " first_name = input(\"Enter your first name\")\n", + " last_name = input(\"Enter your last name\")\n", + "\n", + " return f\"Users name is {first_name} {last_name}\"" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "dcdd1707", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Users name is Julia Gallucci'" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "full_name()" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "beeaa7f5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Green'" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "colour = input(\"What is your favourite color\")\n", + "colour" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "fbd65741", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (3 != 3.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "5581c8d0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7.0 and 32 > 9" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "id": "4b0e4608", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"apple\" != \"Apple\" and 32 > 9" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "9a9efa1f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "30 < 2 and 32 > 9 " + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "ab118b45", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"python\" == \"Python\" or 32 > 9" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "d3b3be56", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7.0 and 3" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "cf7257b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True and False" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "127df33d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True or False" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "851021ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not True" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "7b398535", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not False" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "f63ba968", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "age = 20\n", + "print(age >= 18 and age <= 25)" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "62479111", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "x = 10\n", + "print(x < 5 or x == 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "40284c64", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century\n" + ] + } + ], + "source": [ + "year = 2022\n", + "\n", + "if year >= 2000:\n", + " print(\"We are in the 21st century\")" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "621dc91f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century\n" + ] + } + ], + "source": [ + "year = 2026\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": 101, + "id": "9b594212", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 20th century\n" + ] + } + ], + "source": [ + "year = 1901\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", + "else:\n", + " print(\"We are not in the 20th or 21st century\")" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "8fc2a622", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "B\n" + ] + } + ], + "source": [ + "x = 2\n", + "\n", + "if x > 5:\n", + " print(\"A\")\n", + "else:\n", + " print(\"B\")" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "65bd91e8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "D\n" + ] + } + ], + "source": [ + "score = 54\n", + "\n", + "if score >= 90:\n", + " print(\"A\")\n", + "elif score >= 80:\n", + " print(\"B\")\n", + "elif score >= 70:\n", + " print(\"C\")\n", + "else:\n", + " print(\"D\")" + ] + }, + { + "cell_type": "markdown", + "id": "611a2f8f", + "metadata": {}, + "source": [ + "# Exercise" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "51541685", + "metadata": {}, + "outputs": [], + "source": [ + "def weather_commentary():\n", + " temp = float(input(\"What is the temperature in degrees C?\"))\n", + "\n", + " if temp <= 0:\n", + " print(\"It is freezing cold!\")\n", + " elif temp <= 15:\n", + " print(\"It is cold!\")\n", + " elif temp <= 30:\n", + " print(\"It is hot!\")\n", + " elif temp <= 45:\n", + " print(\"It is very hot!\")\n", + " else:\n", + " print(\"It is extremely hot!\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "c812b39b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It is very hot!\n" + ] + } + ], + "source": [ + "weather_commentary()" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "325ec9c7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You are able to enter!\n" + ] + } + ], + "source": [ + "age = 20\n", + "has_id = True\n", + "\n", + "if age >= 18 and has_id:\n", + " print(\"You are able to enter!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "f60402c8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You get a discount!\n" + ] + } + ], + "source": [ + "is_student = True\n", + "has_coupon = False\n", + "\n", + "if is_student or has_coupon:\n", + " print(\"You get a discount!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "id": "9749126d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You can go outside!\n" + ] + } + ], + "source": [ + "is_raining = False\n", + "\n", + "if not is_raining:\n", + " print(\"You can go outside!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d14ec25f", + "metadata": {}, + "outputs": [], + "source": [ + "age = 20\n", + "has_id = True\n", + "\n", + "if age >= 18:\n", + " if has_id:\n", + " print(\"You are able to enter\")\n", + " else:\n", + " print(\"You need your ID!\")\n", + "else:\n", + " print(\"You are too young!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "id": "545cd218", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Child\n" + ] + } + ], + "source": [ + "age = 12\n", + "\n", + "if age >= 18:\n", + " print(\"Adult\")\n", + "else:\n", + " if age >= 13:\n", + " print(\"Teen\")\n", + " else:\n", + " print(\"Child\")" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "id": "8de1b017", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Distinction\n" + ] + } + ], + "source": [ + "score = 80\n", + "\n", + "if score >= 50:\n", + " if score >= 75:\n", + " print(\"Distinction\")\n", + " else:\n", + " print(\"Pass\")\n", + "else:\n", + " print(\"Fail\")" + ] + } + ], + "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/live_code-04-16-26.ipynb b/04_this_cohort/live-code/live_code-04-16-26.ipynb new file mode 100644 index 000000000..3737a5cbd --- /dev/null +++ b/04_this_cohort/live-code/live_code-04-16-26.ipynb @@ -0,0 +1,2240 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 99, + "id": "c12e6db2", + "metadata": {}, + "outputs": [], + "source": [ + "vowels = ['a','e','i','o','u']" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "7047e737", + "metadata": {}, + "outputs": [], + "source": [ + "empty_list = []" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "fe0d402f", + "metadata": {}, + "outputs": [], + "source": [ + "scores = [90,80,82,91,80]" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "001d70b3", + "metadata": {}, + "outputs": [], + "source": [ + "grades = ['K',1,2,3,4,5,6,7,8,9,10,11,12]" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "e2873a8b", + "metadata": {}, + "outputs": [], + "source": [ + "foods = [\n", + " [\"apple\",\"banana\",\"orange\"],\n", + " [\"carrot\",\"broccoli\",\"spinach\"]\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "377fafc9", + "metadata": {}, + "outputs": [], + "source": [ + "fruits = [\"apple\",\"banana\",\"orange\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "cb040cc5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'apple'" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "303ffc9d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['apple', 'banana']" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits[0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "3798c4e0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "2afe5317", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'j' in vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "8c577691", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(vowels)" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "608db520", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 * vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "id": "b49fe23d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u', 'apple', 'banana', 'orange']" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels + fruits" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "63730184", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['apple', 'banana', 'orange']" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "id": "a9ae71fa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['apple', 'kiwi', 'orange']" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits[1] = \"kiwi\"\n", + "fruits" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "726b185d", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow = [\"red\",\"orange\",\"yellow\",\"green\",\"light blue\",\"blue\",\"violet\"]\n", + "\n", + "rainbow.append(\"purple\")" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "890e70ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red', 'orange', 'yellow', 'green', 'light blue', 'blue', 'violet', 'purple']" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "0a50b6fe", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.extend([\"magenta\",\"pink\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "id": "eb50e31a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'magenta',\n", + " 'pink']" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "id": "e81f9dee", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.extend(\"pink\")" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "id": "f9075787", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'magenta',\n", + " 'pink',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k']" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "0d098b87", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.insert(6,'indigo')" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "id": "4a8a080f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'indigo',\n", + " 'violet',\n", + " 'purple',\n", + " 'magenta',\n", + " 'pink',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k']" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "57793ae4", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow = [\"red\",\"orange\",\"yellow\",\"yellow\",\"green\",\"light blue\",\"blue\",\"violet\"]\n", + "\n", + "rainbow.remove(\"yellow\")" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "id": "12139fe8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red', 'orange', 'yellow', 'green', 'light blue', 'blue', 'violet']" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "7d769d1e", + "metadata": {}, + "outputs": [], + "source": [ + "del rainbow[0:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "id": "4fa2ea6f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['green', 'light blue', 'blue', 'violet']" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "id": "b9a62235", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 3, 4, 7]" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numbers = [4,1,7,3]\n", + "numbers.sort()\n", + "numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "4d8bfc20", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['apple', 'banana', 'kiwi', 'pineapple']" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits = [\"pineapple\",\"apple\",\"kiwi\",\"banana\"]\n", + "fruits.sort()\n", + "fruits" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "id": "20d2a8fa", + "metadata": {}, + "outputs": [], + "source": [ + "numbers = [4,1,7,3]\n", + "\n", + "sorted_numbers = sorted(numbers, reverse=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "id": "6ea01a20", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[4, 1, 7, 3]" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "bee02a9a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[7, 4, 3, 1]" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted_numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "a15bc7e2", + "metadata": {}, + "outputs": [], + "source": [ + "nums = [10,20,30,40,50]" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "069a53e6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[20, 30, 40]" + ] + }, + "execution_count": 132, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nums[1:4]" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "id": "4649bfc8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[10, 20, 30]" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nums[:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "id": "acbc0986", + "metadata": {}, + "outputs": [], + "source": [ + "coordinates = (43.7, -79.4)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "id": "a758d1d2", + "metadata": {}, + "outputs": [], + "source": [ + "empty_tuple = ()" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "id": "45e72981", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(coordinates)" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "id": "7d0785ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-79.4, 43.7]" + ] + }, + "execution_count": 137, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(coordinates)" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "id": "19354c5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(43.7, -79.4)" + ] + }, + "execution_count": 138, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "coordinates" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "id": "97ce4b69", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'tuple' object does not support item assignment", + "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[139]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m nums = (\u001b[32m10\u001b[39m,\u001b[32m20\u001b[39m,\u001b[32m30\u001b[39m,\u001b[32m40\u001b[39m,\u001b[32m50\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43mnums\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m]\u001b[49m = \u001b[32m100\u001b[39m\n", + "\u001b[31mTypeError\u001b[39m: 'tuple' object does not support item assignment" + ] + } + ], + "source": [ + "nums = (10,20,30,40,50)\n", + "nums[0] = 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e00aee3b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3}" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique_numbers = {1,2,3,3,3}\n", + "unique_numbers" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d4806d6f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things = {'coat','lock','box','book','apple','hair','xylophone','lock','book'}\n", + "things" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0cb423fa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'M1M', 'M1T', 'M5R', 'M5V'}" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "postal_codes = ['M5R','M5V','M1M','M1M','M1T']\n", + "set(postal_codes)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1063c06f", + "metadata": {}, + "outputs": [], + "source": [ + "empty_set = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "416ac272", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5895a919", + "metadata": {}, + "outputs": [], + "source": [ + "things.add('lock')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e41f1269", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25a8d635", + "metadata": {}, + "outputs": [], + "source": [ + "things.add('pear')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "06156656", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'pear', 'xylophone'}" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86a29155", + "metadata": {}, + "outputs": [], + "source": [ + "things.remove('pear')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "89fe1a0b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9107cc28", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow = {'red','orange','yellow','green','blue','idigo','violet'}\n", + "\n", + "olympic_flag = {'red','green','yellow','blue','black'}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be82b874", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black', 'blue', 'green', 'idigo', 'orange', 'red', 'violet', 'yellow'}" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.union(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d2178714", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'blue', 'green', 'red', 'yellow'}" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.intersection(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af09c335", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black', 'idigo', 'orange', 'violet'}" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.symmetric_difference(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee83a456", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'idigo', 'orange', 'violet'}" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.difference(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "18ba13c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black'}" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "olympic_flag.difference(rainbow)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7231d6ec", + "metadata": {}, + "outputs": [], + "source": [ + "A = {1,2,3}\n", + "B = {3,4,5}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6c2359c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4, 5}" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.union(B)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7705999b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{3}" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.intersection(B)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c1e91e87", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2}" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.difference(B)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9fd428b4", + "metadata": {}, + "outputs": [], + "source": [ + "#dictionary of capitals\n", + "\n", + "capitals = {\n", + " \"Canada\": \"Ottawa\",\n", + " \"United States\": \"Washington D.C\",\n", + " \"Mexico\" : \"Mexico City\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc9f7a18", + "metadata": {}, + "outputs": [], + "source": [ + "empty_dictionary = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5da8dbd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ottawa'" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals[\"Canada\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "029a4612", + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'Italy'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[71]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mcapitals\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mItaly\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[31mKeyError\u001b[39m: 'Italy'" + ] + } + ], + "source": [ + "capitals[\"Italy\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0489c6c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ottawa'" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals.get(\"Canada\",\"Not found\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8646aa6a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'United States' in capitals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9578fae4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Washington D.C' in capitals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5acdf0c1", + "metadata": {}, + "outputs": [], + "source": [ + "capitals[\"Italy\"] = \"Milan\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c48a5eb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Canada': 'Ottawa',\n", + " 'United States': 'Washington D.C',\n", + " 'Mexico': 'Mexico City',\n", + " 'Italy': 'Milan'}" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6e5bd1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Canada': 'Ottawa',\n", + " 'United States': 'Washington D.C',\n", + " 'Mexico': 'Mexico City',\n", + " 'Italy': 'Rome'}" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals[\"Italy\"] = \"Rome\"\n", + "capitals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c8ade07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Canada': 'Ottawa', 'United States': 'Washington D.C', 'Italy': 'Rome'}" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "del capitals[\"Mexico\"]\n", + "capitals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61a2016b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['Canada', 'United States', 'Italy'])" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe0ed736", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_values(['Ottawa', 'Washington D.C', 'Rome'])" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals.values()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7af6b5f4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('Canada', 'Ottawa'), ('United States', 'Washington D.C'), ('Italy', 'Rome')])" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capitals.items()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4c2ecef2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ottawa is a capital!\n" + ] + } + ], + "source": [ + "if 'Ottawa' in capitals.values():\n", + " print(\"Ottawa is a capital!\")\n", + "else:\n", + " print(\"Ottawa is not a capital\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5a081cf", + "metadata": {}, + "outputs": [], + "source": [ + "students = {\n", + " \"name\":\"Alice\",\n", + " \"age\": 20,\n", + " \"major\": \"Phsyics\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "429de19f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Phsyics'" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "students[\"major\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86fd6e79", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Alice', 'age': 21}" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student = {\n", + " \"name\":\"Alice\",\n", + " \"age\":20\n", + "}\n", + "student[\"age\"] = 21\n", + "student" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ebcd09ab", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['name', 'age'])" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "59eaa300", + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'gender'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mKeyError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[90]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mstudent\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mgender\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[31mKeyError\u001b[39m: 'gender'" + ] + } + ], + "source": [ + "student[\"gender\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d79cf07b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Key not found'" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student.get(\"gender\",\"Key not found\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b3de6706", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Alice', 'age': 21}" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3cb90305", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Alice', 'age': 21, 'grade': 'A'}" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student[\"grade\"] = \"A\"\n", + "student" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "983ff06c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Alice'" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "student.get(\"name\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21166165", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a\n", + "e\n", + "i\n", + "o\n", + "u\n" + ] + } + ], + "source": [ + "vowels = ['a','e','i','o','u']\n", + "\n", + "for vowel in vowels:\n", + " print(vowel)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e93a722", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 0\n", + "1 2\n", + "2 4\n", + "3 6\n", + "4 8\n" + ] + } + ], + "source": [ + "for num in range(5):\n", + " print(num, num*2)" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "86724154", + "metadata": {}, + "outputs": [], + "source": [ + "#list of files\n", + "input_files = ['data_01.csv','data_02.csv','data_03.csv','data_04.csv']\n", + "\n", + "#empty list\n", + "output_files = [] \n", + "\n", + "#for loop\n", + "for file in input_files:\n", + " output_file_name = \"processed_\" + file.replace('.csv','.xlsx')\n", + " output_files.append(output_file_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "id": "ca5e27ba", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['processed_data_01.xlsx',\n", + " 'processed_data_02.xlsx',\n", + " 'processed_data_03.xlsx',\n", + " 'processed_data_04.xlsx']" + ] + }, + "execution_count": 145, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "output_files" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "id": "de5e23db", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple\n", + "banana\n", + "cherry\n" + ] + } + ], + "source": [ + "fruits = ['apple','banana','cherry']\n", + "\n", + "for fruit in fruits:\n", + " print(fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "5a9ac6ee", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n" + ] + } + ], + "source": [ + "for i in range(3):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "id": "65d8f72f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "6\n", + "8\n" + ] + } + ], + "source": [ + "for i in range(1,5):\n", + " print(i*2)" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "c7d268f2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "20\n", + "30\n" + ] + } + ], + "source": [ + "numbers = [10,20,30]\n", + "\n", + "for num in numbers:\n", + " print(num)" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "id": "e7977363", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "for i in range(1,6):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "492a859e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Stop 1 is Sheppard-Yonge\n", + "Stop 2 is Bayview\n", + "Stop 3 is Bessarion\n", + "Stop 4 is Leslie\n", + "Stop 5 is Don Mills\n" + ] + } + ], + "source": [ + "stops = [\"Sheppard-Yonge\",\n", + "\"Bayview\",\n", + "\"Bessarion\",\n", + "\"Leslie\",\n", + "\"Don Mills\"]\n", + "\n", + "\n", + "for idx, stop in enumerate(stops):\n", + " print(f\"Stop {idx + 1} is {stop}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "id": "71875e84", + "metadata": {}, + "outputs": [], + "source": [ + "prices = {\n", + " \"apple\": 2,\n", + " \"banana\": 1,\n", + " \"orange\": 3\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "id": "265ef2f8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('apple', 2), ('banana', 1), ('orange', 3)])" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prices.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 158, + "id": "797b5d25", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple costs: $2\n", + "Low price\n", + "orange costs: $3\n" + ] + } + ], + "source": [ + "for fruit, price in prices.items():\n", + " if price == 1:\n", + " print(\"Low price\")\n", + " else:\n", + " print(f\"{fruit} costs: ${price}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "a7453253", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 apple\n", + "1 banana\n", + "2 cherry\n" + ] + } + ], + "source": [ + "for idx, fruit in enumerate(fruits):\n", + " print(idx,fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "id": "8c5d4351", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 apple\n", + "1 banana\n", + "2 cherry\n" + ] + } + ], + "source": [ + "fruits = [\"apple\",\"banana\",\"cherry\"]\n", + "\n", + "for index, fruit in enumerate(fruits):\n", + " print(index, fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "id": "8920fc21", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Alice\n", + "1 Bob\n", + "2 Charlie\n" + ] + } + ], + "source": [ + "names = [\"Alice\",\"Bob\",\"Charlie\"]\n", + "\n", + "for index,name in enumerate(names):\n", + " print(index,name)" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "id": "f55d5312", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "name Alice\n", + "age 20\n" + ] + } + ], + "source": [ + "student = {\n", + " \"name\":\"Alice\",\n", + " \"age\": 20\n", + "}\n", + "\n", + "for key,value in student.items():\n", + " print(key,value)" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "id": "ebae45b0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "outer loop:1\n", + "inner loop:1\n", + "inner loop:2\n", + "inner loop:3\n", + "inner loop:4\n", + "inner loop:5\n", + "inner loop:6\n", + "inner loop:7\n", + "inner loop:8\n", + "inner loop:9\n", + "outer loop:2\n", + "inner loop:1\n", + "inner loop:2\n", + "inner loop:3\n", + "inner loop:4\n", + "inner loop:5\n", + "inner loop:6\n", + "inner loop:7\n", + "inner loop:8\n", + "inner loop:9\n" + ] + } + ], + "source": [ + "for i in range(1,3):\n", + " print(f\"outer loop:{i}\")\n", + " for j in range(1,10):\n", + " print(f\"inner loop:{j}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "id": "97afde25", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "outer1,inner1\n", + "outer1,inner2\n", + "outer1,inner3\n", + "outer1,inner4\n", + "outer1,inner5\n", + "outer1,inner6\n", + "outer1,inner7\n", + "outer1,inner8\n", + "outer1,inner9\n", + "outer2,inner1\n", + "outer2,inner2\n", + "outer2,inner3\n", + "outer2,inner4\n", + "outer2,inner5\n", + "outer2,inner6\n", + "outer2,inner7\n", + "outer2,inner8\n", + "outer2,inner9\n" + ] + } + ], + "source": [ + "for i in range(1,3):\n", + " for j in range(1,10):\n", + " print(f\"outer{i},inner{j}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "id": "e240f043", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 1\n", + "1 2\n", + "2 1\n", + "2 2\n", + "3 1\n", + "3 2\n" + ] + } + ], + "source": [ + "for i in range(1,4):\n", + " for j in range(1,3):\n", + " print(i,j)" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "id": "e0454c23", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "3\n", + "2\n", + "1\n" + ] + } + ], + "source": [ + "counter = 4\n", + "\n", + "while counter > 0:\n", + " print(counter)\n", + " #counter = counter - 1\n", + " counter -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 179, + "id": "c400fd1b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "3\n" + ] + } + ], + "source": [ + "counter = 4\n", + "\n", + "while counter > 0:\n", + " print(counter)\n", + " if counter == 3:\n", + " break\n", + " counter -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 182, + "id": "b42a13ca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "3\n", + "5\n" + ] + } + ], + "source": [ + "for i in range(1,6):\n", + " if i % 2 == 0:\n", + " continue\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 183, + "id": "5efafbe7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "i = 1\n", + "\n", + "while i <= 5:\n", + " print(i)\n", + " i += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "id": "a577012b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "i = 1\n", + "while True:\n", + " i += 1\n", + " print(i)\n", + " if i == 4:\n", + " break" + ] + } + ], + "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 +} From ebecee3e046f796043edcbc239e3b38bedab698c Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Sat, 18 Apr 2026 22:13:09 -0400 Subject: [PATCH 3/4] Finalize assignment_1 notebook --- 02_activities/assignments/assignment_1.ipynb | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index de865599f..de1557e26 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -130,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -139,22 +139,27 @@ "True" ] }, - "execution_count": 5, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - "# This function returns True if the words are anagrams and False if they are not. The function also takes into account whether the anagram check should be case sensitive or not based on the value of is_case_sensitive.\n", - " return sorted(word_a) == sorted(word_b) if is_case_sensitive else sorted(word_a.lower()) == sorted(word_b.lower())\n", + "# This function returns True if the words are anagrams and False if they are not.\n", + "# It accounts for case sensitivity based on the is_case_sensitive boolean.\n", + " if is_case_sensitive:\n", + " return sorted(word_a) == sorted(word_b)\n", + " else:\n", + " # Convert both to lowercase to ignore case differences\n", + " return sorted(word_a.lower()) == sorted(word_b.lower())\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -163,7 +168,7 @@ "False" ] }, - "execution_count": 6, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -174,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -183,7 +188,7 @@ "False" ] }, - "execution_count": 7, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } From 2f9d52948c9b6ed3985844b40f85b61c10c39d46 Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Sun, 26 Apr 2026 21:31:05 -0400 Subject: [PATCH 4/4] Complete Assignment 2: Arthritis Drug Analysis --- 02_activities/assignments/assignment_2.ipynb | 193 +++++++++++++++++-- 1 file changed, 174 insertions(+), 19 deletions(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index e214ff9e4..69df1fa22 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -72,11 +72,138 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "\n", + "0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n", + "\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n", + "\n" + ] + } + ], "source": [ "all_paths = [\n", " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", @@ -95,8 +222,10 @@ "\n", "with open(all_paths[0], 'r') as f:\n", " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " content = f.readlines()\n", + " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n", + " for row in content:\n", + " print(row)\n" ] }, { @@ -130,13 +259,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "id": "82-bk4CBB1w4" }, "outputs": [], "source": [ + "from tkinter.messagebox import IGNORE\n", + "\n", "import numpy as np\n", + "from plotly import data\n", "\n", "def patient_summary(file_path, operation):\n", " data = np.loadtxt(fname=file_path, delimiter=',') # Load the data from the file\n", @@ -145,27 +277,34 @@ " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n", - "\n", + " summary_values = np.mean (data, axis=ax)\n", " elif operation == 'max':\n", " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.max(data, axis=ax)\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.min(data, axis=ax)\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", - "\n", " return summary_values" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -228,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "_svDiRkdIwiT" }, @@ -251,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "id": "LEYPM5v4JT0i" }, @@ -261,15 +400,30 @@ "\n", "def detect_problems(file_path):\n", " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", - "\n", - " return" + " #use patient_summary() to get the means for the file path and store it in a variable called patient_means\n", + " patient_means = patient_summary(file_path, 'mean')\n", + " #use check_zeros() to check for zeros in the means and store the result in a variable called has_issue\n", + " has_issue = check_zeros(patient_means)\n", + " \n", + " #YOUR CODE HERE: If check_zeros() returns True, print a warning message and return the means, else just return the means\n", + " if has_issue:\n", + " print(\"Warning: At least one patient has a mean of 0, which may indicate a problem with the data.\")\n", + " return has_issue" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", @@ -314,7 +468,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +482,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.15" } }, "nbformat": 4,