From df446d7659be54c9a7827b2ac049d98f7514a127 Mon Sep 17 00:00:00 2001 From: Tom Dudgeon Date: Fri, 13 Mar 2026 14:10:57 -0400 Subject: [PATCH 1/2] committing assignment 1 --- 02_activities/assignments/assignment_1.ipynb | 307 ++++++++++++++++++- 1 file changed, 293 insertions(+), 14 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 2dca19d0b..4487a59a6 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -58,11 +58,36 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 29, + "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", + " # make letters lower case in word_a and word_b for easier comparison\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " # Check if word_a and word_b are the same length\n", + " if len(word_a) != len(word_b):\n", + " # If the words are of different lengths, return the following line\n", + " return \"Word lengths do not match :( \"\n", + " # If the words are the same length, sort the words alphabetically and see if they match to one another\n", + " if sorted(word_a) == sorted(word_b):\n", + " # If they match, return the following line\n", + " return \"True\"\n", + " else:\n", + " # If they do not match, return the following line\n", + " return \"False\"\n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,22 +95,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Word lengths do not match :( '" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "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": [ "anagram_checker(\"night\", \"Thing\")" ] }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"night\", \"thing\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -99,10 +166,52 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "# This block was me learning the functionality and is very long, the function I made in the next block is the better version\n", + "\n", "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " # If is_case_sensitive == False, run the following block of code\n", + " if is_case_sensitive == False:\n", + " # make letters lower case in word_a and word_b for easier comparison\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " # Check if word_a and word_b are the same length\n", + " if len(word_a) != len(word_b):\n", + " # If the words are of different lengths, return the following line\n", + " return \"Word lengths do not match :( \"\n", + " # If the words are the same length, sort the words alphabetically and see if they match to one another\n", + " if sorted(word_a) == sorted(word_b):\n", + " # If they match, return the following line\n", + " return \"True\"\n", + " else:\n", + " # If they do not match, return the following line\n", + " return \"False\"\n", + " # If is_case_sensitive == True, run the following block of code\n", + " elif is_case_sensitive == True:\n", + " # Check if word_a and word_b are the same length\n", + " if len(word_a) != len(word_b):\n", + " # If the words are of different lengths, return the following line\n", + " return \"Word lengths do not match :( \"\n", + " # If the words are the same length, sort the words alphabetically and see if they match to one another\n", + " if sorted(word_a) == sorted(word_b):\n", + " # If they match, return the following line\n", + " return \"True\"\n", + " else:\n", + " # If they do not match, return the following line\n", + " return \"False\"\n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" @@ -114,16 +223,186 @@ "metadata": {}, "outputs": [], "source": [ - "anagram_checker(\"Silent\", \"listen\", True) # False" + "# PLEASE MARK THIS BLOCK OF CODE-------------------------------------------------------\n", + "# This is the condensed code using an 'if not' statement that is more streamlined but achieves the same results as the block above\n", + "\n", + "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + " # If is_case_sensitive is set to False, run the following if statement\n", + " # It converts all letters to lower case for comparison.\n", + " # Otherwise (i.e., is_case_sensitive is set to True) the if statement is skipped\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " # Check if word_a and word_b are the same length\n", + " if len(word_a) != len(word_b):\n", + " # If the words are of different lengths, return the following line\n", + " return \"Word lengths do not match :( \"\n", + " # If the words are the same length, sort the words alphabetically and see if they match to one another\n", + " if sorted(word_a) == sorted(word_b):\n", + " # If they match, return the following line\n", + " return \"True\"\n", + " else:\n", + " # If they do not match, return the following line\n", + " return \"False\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'False'" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if Silent and listen are anagrams, case sensitive\n", + "anagram_checker(\"Silent\", \"listen\", True)\n", + "\n", + "# Should produce 'False', because of captial 'S' and lower case 'l'" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if Silent and listen are anagrams, case doesn't matter\n", + "anagram_checker(\"Silent\", \"listen\", False)\n", + "\n", + "# Should produce 'True', because case sensitivity doesn't matter" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'False'" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if TomMarvoloRiddle and IamLordVoldemort are anagrams, case sensitive\n", + "anagram_checker(\"TomMarvoloRiddle\", \"IamLordVoldemort\", True)\n", + "\n", + "# Should produce 'False', because of the capital letters" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if TomMarvoloRiddle and IamLordVoldemort are anagrams, case doesn't matter\n", + "anagram_checker(\"TomMarvoloRiddle\", \"IamLordVoldemort\", False)\n", + "\n", + "# Should produce 'True', because case sensitivity doesn't matter" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'False'" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if ElvisPresley and PresleyLives are anagrams, case sensitive\n", + "anagram_checker(\"ElvisPresley\", \"PresleyLives\", True)\n", + "\n", + "# Should produce 'False', because of the capital letters" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check if ElvisPresley and PresleyLives are anagrams, case doesn't matter\n", + "anagram_checker(\"ElvisPresley\", \"PresleyLives\", False)\n", + "\n", + "# Should produce 'True', because case sensitivity doesn't matter" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Word lengths do not match :( '" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "# A dummy test to see if the output still works when words are completely mismatched\n", + "anagram_checker(\"thisisatest\", \"pleasepassme\", False)" ] }, { @@ -139,7 +418,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -153,7 +432,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4, From b458ffab42ac92237453ad371959a7fb5b8a94b9 Mon Sep 17 00:00:00 2001 From: Tom Dudgeon Date: Fri, 20 Mar 2026 13:50:54 -0400 Subject: [PATCH 2/2] committing assignment 1 --- 02_activities/assignments/assignment_1.ipynb | 56 ++++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 4487a59a6..22df0803b 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "'True'" ] }, - "execution_count": 29, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -95,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -104,7 +104,7 @@ "'Word lengths do not match :( '" ] }, - "execution_count": 30, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -115,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -124,7 +124,7 @@ "'True'" ] }, - "execution_count": 31, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -135,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -144,7 +144,7 @@ "'True'" ] }, - "execution_count": 32, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -164,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -173,7 +173,7 @@ "'True'" ] }, - "execution_count": 34, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -219,11 +219,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# PLEASE MARK THIS BLOCK OF CODE-------------------------------------------------------\n", + "# THIS IS THE SHORTER FUNCTION WITH SAME FUNCTIONALITY -------------------------------------------------------\n", "# This is the condensed code using an 'if not' statement that is more streamlined but achieves the same results as the block above\n", "\n", "def anagram_checker(word_a, word_b, is_case_sensitive):\n", @@ -248,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -257,7 +257,7 @@ "'False'" ] }, - "execution_count": 60, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -271,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -280,7 +280,7 @@ "'True'" ] }, - "execution_count": 61, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -294,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -303,7 +303,7 @@ "'False'" ] }, - "execution_count": 62, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -317,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -326,7 +326,7 @@ "'True'" ] }, - "execution_count": 63, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -340,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -349,7 +349,7 @@ "'False'" ] }, - "execution_count": 64, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -363,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -372,7 +372,7 @@ "'True'" ] }, - "execution_count": 65, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -386,7 +386,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -395,7 +395,7 @@ "'Word lengths do not match :( '" ] }, - "execution_count": 67, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -418,7 +418,7 @@ ], "metadata": { "kernelspec": { - "display_name": "python-env", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -432,7 +432,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.14" + "version": "3.12.0" } }, "nbformat": 4,