From a309ef773833af23a11ab17962e037201f3cd971 Mon Sep 17 00:00:00 2001 From: Shaifali Tailor Date: Fri, 28 Nov 2025 11:09:30 -0500 Subject: [PATCH] Python Assignment 1 completed --- 02_activities/assignments/assignment_1.ipynb | 106 ++++++- 1_Functions.ipynb | 214 ++++++++++++++ 2_Method.ipynb | 238 +++++++++++++++ 3_Strings.ipynb | 174 +++++++++++ 4_operators.ipynb | 201 +++++++++++++ 5_conditions.ipynb | 267 +++++++++++++++++ 6_lists.ipynb | 290 +++++++++++++++++++ 7 files changed, 1478 insertions(+), 12 deletions(-) create mode 100644 1_Functions.ipynb create mode 100644 2_Method.ipynb create mode 100644 3_Strings.ipynb create mode 100644 4_operators.ipynb create mode 100644 5_conditions.ipynb create mode 100644 6_lists.ipynb diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 625be0241..495f91804 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "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", + " #word_a = word_a.lower()\n", + " #word_b = word_b.lower()\n", + " a = sorted(word_a.lower())\n", + " b = sorted(word_b.lower())\n", + " if a == b:\n", + " return True\n", + " else:\n", + " return False\n", + "\n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +91,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,12 +140,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", + " a = sorted(word_a)\n", + " b = sorted(word_b)\n", + " if is_case_sensitive:\n", + " if a == b:\n", + " return True\n", + " else:\n", + " return False\n", + " elif is_case_sensitive == False:\n", + " a = sorted(word_a.lower())\n", + " b = sorted(word_b.lower())\n", + " if a == b:\n", + " return True\n", + " else:\n", + " return False\n", + "\n", + " \n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" @@ -110,9 +181,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -130,7 +212,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -144,7 +226,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4, diff --git a/1_Functions.ipynb b/1_Functions.ipynb new file mode 100644 index 000000000..eb305b1b9 --- /dev/null +++ b/1_Functions.ipynb @@ -0,0 +1,214 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "e8686024", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(divident,divisor):\n", + " result = divident / divisor\n", + " return result\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "dca148b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.0" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(10,5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "92d87af4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.65\n", + "0.4\n" + ] + } + ], + "source": [ + "# default value assignment\n", + "\n", + "def calc_sales_tax(price, tax_rate=0.13):\n", + " sales_tax = price * tax_rate\n", + " return sales_tax\n", + "\n", + "print(calc_sales_tax(5))\n", + "print(calc_sales_tax(5,0.08)) # this overrides the default value\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "16cb9446", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "256.0\n", + "262.0\n" + ] + } + ], + "source": [ + "# keyword arguments, position of the supplied parameters while calling the function is important\n", + "# docstring using 3 single quote \n", + "def calc_total_bill(price, tax_rate=0.13,tip_rate=0.15):\n", + " '''Calculate total bill with tax and tip'''\n", + " tax = price * tax_rate\n", + " tip = price * tip_rate\n", + " total = price + tax + tip\n", + " return total\n", + "\n", + "print(calc_total_bill(200))\n", + "\n", + "print(calc_total_bill(200,tip_rate=0.18)) # position of argument matter so kerword argument is used" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "8b5db084", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function calc_total_bill in module __main__:\n", + "\n", + "calc_total_bill(price, tax_rate=0.13, tip_rate=0.15)\n", + " Calculate total bill with tax and tip\n", + "\n" + ] + } + ], + "source": [ + "# docstring - creating help text for functions\n", + "\n", + "help(calc_total_bill)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c127b2b6", + "metadata": {}, + "outputs": [], + "source": [ + "# variable scope\n", + "# variables within functions are local - only access it within that function and not outside\n", + "# You can explicitely define global variables within function using the keyword global" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "75086155", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate=0.13, tip_rate=\"standard\"):\n", + "\n", + " tip_presets = {\n", + "\n", + " \"low\": 0.10,\n", + "\n", + " \"standard\": 0.15,\n", + "\n", + " \"high\": 0.20\n", + "\n", + " }\n", + "\n", + " \n", + "\n", + " # only convert if it's one of the known presets\n", + "\n", + " if tip_rate in tip_presets:\n", + "\n", + " tip_rate = tip_presets[tip_rate]\n", + "\n", + " \n", + "\n", + " tax = price * tax_rate\n", + "\n", + " tip = price * tip_rate\n", + "\n", + " total = price + tax + tip\n", + "\n", + " return total" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4ce3079b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n", + "51\n" + ] + } + ], + "source": [ + "# input function - always takes in value as string\n", + "\n", + "age = input('How old are you?')\n", + "\n", + "print(age)\n", + "\n", + "age_next_bday = (int(age) + 1)\n", + "print(age_next_bday)" + ] + } + ], + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/2_Method.ipynb b/2_Method.ipynb new file mode 100644 index 000000000..7984fc760 --- /dev/null +++ b/2_Method.ipynb @@ -0,0 +1,238 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "b7d75098", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLLING'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# method is a function that only works for a specific data type\n", + "# syntax is object.method_name(parameters)\n", + "# https://docs.python.org/3/library/stdtypes.html#string-methods\n", + "\n", + "\n", + "\"I am not yellling\".upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "eafa0878", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"this string is unusual\".count('e')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "23c7fbdc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'file_name.csv'.endswith('.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "707947f1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'long_file_name_with_spaces.csv'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'long file name with spaces.csv'.replace(' ','_')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "129be9c7", + "metadata": {}, + "outputs": [], + "source": [ + "first_name = 'Ada'\n", + "last_name = 'Lovelace'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07e95144", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# formating string methods\n", + "# .format() string method\n", + "\n", + "'Ada Lovelace\\'s initials are {}. {}.'.format(first_name[0], last_name[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "8a439816", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favourite day of the week is Monday.'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "day_of_week = 'Monday'\n", + "'My favourite day of the week is {}.'.format(day_of_week)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "7b2c4093", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# f-string method\n", + "f'Ada Lovelace\\'s initials are {first_name[0]}. {last_name[0]}.'\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "5f6c3050", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favourite sport is soccer'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "favourite_sport = 'soccer'\n", + "\n", + "f'My favourite sport is {favourite_sport}'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a3268d13", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# you can nest methods\n", + "'first_name'.upper().count('F') " + ] + } + ], + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/3_Strings.ipynb b/3_Strings.ipynb new file mode 100644 index 000000000..ee5c82eb5 --- /dev/null +++ b/3_Strings.ipynb @@ -0,0 +1,174 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "36f2bfdb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mashed Potatoes\n" + ] + } + ], + "source": [ + "# you can use double or single quotes to define string\n", + "\n", + "favourite_food = 'Mashed Potatoes'\n", + "print(favourite_food)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "356b9482", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "let's see if this works\n" + ] + } + ], + "source": [ + "a = \"let's see if this works\"\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "6804df00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I am a multiline string\\nI span over many\\nmany\\nmany\\nlines'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# multiline string can be assigned using 3 single/double quotes\n", + "# \\n in the result means new line, \\t tab, \\' single quote, \\\" double quote\n", + "'''I am a multiline string\n", + "I span over many\n", + "many\n", + "many\n", + "lines'''" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "94e77062", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this is \t a tab\n" + ] + } + ], + "source": [ + "print(\"this is \\t a tab\")" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ccfad329", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this is \\ a backslash\n" + ] + } + ], + "source": [ + "print(\"this is \\\\ a backslash\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b9241c1e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this is \" a double quote\n" + ] + } + ], + "source": [ + "print(\"this is \\\" a double quote\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "6b1f63c8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "listic\n" + ] + } + ], + "source": [ + "word1 = \"supercalifragilisticexpialidocious\"\n", + "\n", + "n = len(word1)\n", + "\n", + "middle6 = word1[n//2 - 3 : n//2 + 3]\n", + "\n", + "print(middle6)\n", + "\n", + "#long_word[int((len(long_word)/2))-3:int((len(long_word)/2))+3] \n", + "# Length = 34 letters,middle_letters = word[17-3 : 17+3]\n", + "#print(middle_letters)" + ] + } + ], + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/4_operators.ipynb b/4_operators.ipynb new file mode 100644 index 000000000..2c8df08b2 --- /dev/null +++ b/4_operators.ipynb @@ -0,0 +1,201 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "67c28fb5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Logic operators\n", + "\n", + "# not : negate the truth value of the statement\n", + "\n", + "not True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "ce8810cc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not False" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f1c29595", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (3 == 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "260026c9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n", + "False\n" + ] + } + ], + "source": [ + "# and operator - going to check if the statements on both sides are true\n", + "\n", + "# T T = T\n", + "# F T = F\n", + "# T F = F\n", + "# F F = F\n", + "\n", + "print(True and True)\n", + "print(False and True)\n", + "print(True and False)\n", + "print(False and False)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "862858ed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(7 == 7.0) and (32 > 9)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6a58995e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "# or operator checkes if one of the statements are true\n", + "\n", + "print(True or True)\n", + "print(False or True)\n", + "print(True or False)\n", + "print(False or False)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8663bf6f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# in python 0 is considered false\n", + "0 == False" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6dd5c3f1", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/5_conditions.ipynb b/5_conditions.ipynb new file mode 100644 index 000000000..6ede638fb --- /dev/null +++ b/5_conditions.ipynb @@ -0,0 +1,267 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "a186d670", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "we are not in the 21st century.\n" + ] + } + ], + "source": [ + "year = 1990\n", + "output = 'yes'\n", + "\n", + "if year >= 2000 and output == 'yes': \n", + " print('we are in the 21st century.')\n", + "else:\n", + " print('we are not in the 21st century.')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "05a061fa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "we have gone way back in time\n" + ] + } + ], + "source": [ + "# elif - shortform of else if\n", + "\n", + "year = 1700\n", + "\n", + "if year >= 2000:\n", + " print('we are in the 21st century')\n", + "elif year >= 1900:\n", + " print('we are in the 20th century')\n", + "elif year >= 1800:\n", + " print('we are in the 19th century')\n", + "else:\n", + " print('we have gone way back in time')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "ee3a21e8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Weekday\n" + ] + } + ], + "source": [ + "day_of_week = 'Thursday'\n", + "\n", + "if day_of_week == 'Saturday' or day_of_week == 'Sunday':\n", + " print('Weekend')\n", + "else:\n", + " print('Weekday')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "acdd2070", + "metadata": {}, + "outputs": [], + "source": [ + "def eye_exam_covered(age, qualifying_condition, time_since_last_exam):\n", + " # Assumptions:\n", + " # age is an integer\n", + " # Qualifying conditon is boolean - true if you have eligible medical condition\n", + " # time_since_last_exam integer, number of months since last examination\n", + "\n", + " if 0 <= age <= 19:\n", + " if time_since_last_exam >= 12:\n", + " return \"You are eligible for 1 major eye exam and any minor assessments needed\"\n", + " else:\n", + " return \"It hasn't been 12 months since your last major eye exam but you can have a minor assessment\"\n", + " \n", + " elif 20 <= age <=64:\n", + " if qualifying_condition:\n", + " if time_since_last_exam >= 12:\n", + " return \"You are eligible for one major eye exam and 2 additional followup minor assessments\"\n", + " else:\n", + " return \"it has'nt been 12 months since your last eye exam, but you have follow-up minor assessement\"\n", + " else:\n", + " return 'You dont have an eligible medical condition'\n", + " \n", + " elif age >=65:\n", + " if time_since_last_exam >=18:\n", + " return \"You are eligible for 1 major eye exam and 2 followup minor assessment\"\n", + " else:\n", + " return \"It has not been 18 minths since your last eye exam\"\n", + "\n", + " else:\n", + " return \"Invalid age input\" \n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "10709b63", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for 1 major eye exam and any minor assessments needed'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(19,False,14)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "b7a7cf4e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"It hasn't been 12 months since your last major eye exam but you can have a minor assessment\"" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(15,True,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "21404b2d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You dont have an eligible medical condition'" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(23,False,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "ec054d5a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'It has not been 18 minths since your last eye exam'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(65, True,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "26d502c8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for one major eye exam and 2 additional followup minor assessments'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(50,True,18)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "4ff436ee", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Invalid age input'" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(-10,True, 10)" + ] + } + ], + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/6_lists.ipynb b/6_lists.ipynb new file mode 100644 index 000000000..29491f2e2 --- /dev/null +++ b/6_lists.ipynb @@ -0,0 +1,290 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "36620364", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels = ['a','e','i','o','u']\n", + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "0afb256a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[90, 80, 82, 91, 81]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "score = [90,80,82,91,81]\n", + "score" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "be32c29f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades = ['K',1,2,3,4,5,6,7,8,9,10,11,12]\n", + "grades" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "a8dc45c3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "summary_functions = [len,sum,max,min]\n", + "summary_functions" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "abb1273d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n", + "[]\n" + ] + } + ], + "source": [ + "empty_list = []\n", + "\n", + "empty_list_2 = list()\n", + "\n", + "print(empty_list)\n", + "print(empty_list_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "924e5687", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['Sherlock', 'Watson'], ['Scooby', 'Shaggy', 'Fred'], 'Nancy Drew']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# list within a list\n", + "\n", + "mystery_solvers = [['Sherlock','Watson'],\n", + " ['Scooby','Shaggy','Fred'],\n", + " 'Nancy Drew']\n", + "mystery_solvers" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "a83b6c68", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'e', 'i', 'o', 'u']\n", + "a\n", + "['e', 'i']\n", + "o\n" + ] + } + ], + "source": [ + "# we can slice lists or access list items using index\n", + "\n", + "print(vowels)\n", + "print(vowels[0])\n", + "print(vowels[1:3])\n", + "print(vowels[-2])" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "b1386b9d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 15, 100, 49]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# lists are mutable - so you can change the value in a list\n", + "\n", + "perfect_squares = [1,4,9,16,15,30,49]\n", + "\n", + "perfect_squares[5] = 100\n", + "\n", + "perfect_squares" + ] + }, + { + "cell_type": "markdown", + "id": "60bc4b0a", + "metadata": {}, + "source": [ + "Immutable: Can't be changed after creation. \n", + "\n", + "Examples: int, float, str. \n", + "\n", + "In memory: Reassignment creates a new object. Original stays unchanged.\n", + "\n", + "Mutable: Can be changed in place. \n", + "\n", + "Examples: list. \n", + "\n", + "In memory: Changes affect the same object, changes affect all references to the object." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a05a0b19", + "metadata": {}, + "outputs": [], + "source": [ + "combo = ['burger', 'fries', 'drink']\n", + "kid_meal = list(combo)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "14970692", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['chicken sandwich', 'fries', 'drink']\n", + "['burger', 'fries', 'drink']\n" + ] + } + ], + "source": [ + "combo[0] = 'chicken sandwich'\n", + "print(combo)\n", + "print(kid_meal)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "254f9e4a", + "metadata": {}, + "outputs": [], + "source": [ + "# list operations\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7aa555fd", + "metadata": {}, + "outputs": [], + "source": [ + "# list methods" + ] + } + ], + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}