From 22658d6e9bdd024b53dfa4e137a47eca808208e9 Mon Sep 17 00:00:00 2001 From: Ofir Date: Tue, 21 Oct 2025 12:33:54 -0400 Subject: [PATCH 1/6] I completed assignment 1 and built the anagrams' codes --- 02_activities/assignments/assignment_1.ipynb | 263 ++++++++++++++++++- 1 file changed, 251 insertions(+), 12 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bee48d5a0..0b15eb2a0 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "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", + " '''checks if two strings are anagrams'''\n", + " if type (word_a) == type (word_b) == str:\n", + " if len (word_a) == len (word_b):\n", + " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + "\n", + "\n", + "#explanation: \n", + "# The first conditional ensures that the data type is a string, allowing for the use of string methods on the data.\n", + "# The second conditional aims to determine if the length of the string referred to by the parameter \"word_a\" is equal to that referred to by \"word_b\".\n", + "# The third conditional employs two string methods on each of the parameters. First, the \"sorted\" method breaks each string into a set comprising all its characters.\n", + "# Second, the method \"lower\" ensures that all the characters appearing in each of the strings will appear as lowercase. \n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,22 +101,144 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"time\", \"item\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"time\", \"itex\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"enclosE\", \"Closeen\")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"Ofir\", \"Rifo\")" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"ofif\", \"fif\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -97,26 +250,107 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", "\n", + " '''checks if two strings are anagrams, with an option to select case sensitivity'''\n", + " if type (word_a) == type (word_b) == str:\n", + " if len (word_a) == len (word_b):\n", + " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", + " if (is_case_sensitive) == False:\n", + " return True\n", + " else: \n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + "\n", + "\n", + "\n", + "\n", + "\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": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"Ofir\", \"Rifo\", True)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"Ofir\", \"Rifo\", False)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -126,11 +360,16 @@ "|Code Execution|All code cells execute without errors.|Any code cell produces an error upon execution.|\n", "|Code Quality|Code is well-organized, concise, and includes necessary comments for clarity. E.g. Great use of variable names.|Code is unorganized, verbose, or lacks necessary comments. E.g. Single character variable names outside of loops.|" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -144,7 +383,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.13" } }, "nbformat": 4, From 6077fe5105456cc6f692b8db06a9eabd98c347a5 Mon Sep 17 00:00:00 2001 From: Ofir Date: Thu, 23 Oct 2025 21:08:41 -0400 Subject: [PATCH 2/6] I have revised the assigment --- 02_activities/assignments/assignment_1.ipynb | 127 ++++++++++++++----- 1 file changed, 92 insertions(+), 35 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 0b15eb2a0..17b424923 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -110,7 +110,7 @@ "False" ] }, - "execution_count": 42, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -121,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -130,7 +130,7 @@ "True" ] }, - "execution_count": 43, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -150,7 +150,7 @@ "True" ] }, - "execution_count": 44, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -161,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -170,7 +170,7 @@ "False" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -181,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -190,7 +190,7 @@ "True" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -201,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -210,7 +210,7 @@ "True" ] }, - "execution_count": 51, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -221,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -230,7 +230,7 @@ "False" ] }, - "execution_count": 52, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -250,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -259,38 +259,55 @@ "True" ] }, - "execution_count": 17, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + " \n", " # Modify your existing code here\n", - "\n", + " \n", " '''checks if two strings are anagrams, with an option to select case sensitivity'''\n", " if type (word_a) == type (word_b) == str:\n", " if len (word_a) == len (word_b):\n", - " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", - " if (is_case_sensitive) == False:\n", - " return True\n", - " else: \n", + " if is_case_sensitive == False:\n", + " sorted (word_a.lower()) == sorted (word_b.lower())\n", + " return True\n", + " if is_case_sensitive == True:\n", + " sorted (word_a) != sorted (word_b)\n", " return False\n", - " else:\n", + " else: \n", " return False\n", - " else:\n", - " return False\n", " else:\n", - " return False\n", - "\n", - "\n", - "\n", + " return False\n", "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Listen\", True) # False" + ] + }, { "cell_type": "code", "execution_count": 12, @@ -308,7 +325,27 @@ } ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "anagram_checker (\"Ofir\", \"Rifo\", True)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"Ofir\", \"Rifo\", False)" ] }, { @@ -328,12 +365,12 @@ } ], "source": [ - "anagram_checker (\"Ofir\", \"Rifo\", True)" + "anagram_checker (\"erased\", \"Sedra\", True)" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -342,13 +379,33 @@ "True" ] }, - "execution_count": 16, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "anagram_checker (\"Ofir\", \"Rifo\", False)" + "anagram_checker (\"mate\", \"Tame\", False)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"tiMe\", \"miTe\", False)" ] }, { From 8dc072be43165b5c29985c6c24802cdd3def8b2c Mon Sep 17 00:00:00 2001 From: Ofir Date: Sun, 26 Oct 2025 11:17:23 -0400 Subject: [PATCH 3/6] one last revision --- 02_activities/assignments/assignment_1.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 17b424923..baf0f8fba 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -390,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [ { From 7b5a519eabdf21b0e6ebde964008f3c178dfd7c5 Mon Sep 17 00:00:00 2001 From: Ofir Date: Sun, 26 Oct 2025 11:30:37 -0400 Subject: [PATCH 4/6] one last version. I revised the second part, changed the line 6 code from 'if' to 'else' --- 02_activities/assignments/assignment_1.ipynb | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index baf0f8fba..4fbc39b0a 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -250,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -259,7 +259,7 @@ "True" ] }, - "execution_count": 10, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -275,7 +275,7 @@ " if is_case_sensitive == False:\n", " sorted (word_a.lower()) == sorted (word_b.lower())\n", " return True\n", - " if is_case_sensitive == True:\n", + " else: \n", " sorted (word_a) != sorted (word_b)\n", " return False\n", " else: \n", @@ -290,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -299,7 +299,7 @@ "False" ] }, - "execution_count": 11, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -310,7 +310,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -319,7 +319,7 @@ "False" ] }, - "execution_count": 12, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -350,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -359,13 +359,13 @@ "False" ] }, - "execution_count": 15, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "anagram_checker (\"erased\", \"Sedra\", True)" + "anagram_checker (\"erased\", \"Sedrea\", True)\n" ] }, { @@ -390,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -399,7 +399,7 @@ "True" ] }, - "execution_count": 18, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } From 4c0dbee811150ac9f75bf01137d68e865c23c5cb Mon Sep 17 00:00:00 2001 From: Ofir Date: Mon, 27 Oct 2025 16:46:37 -0400 Subject: [PATCH 5/6] I hope that now it is okay --- 02_activities/assignments/assignment_1.ipynb | 66 ++++++++++++++------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 4fbc39b0a..ba2510f0b 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -250,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -259,7 +259,7 @@ "True" ] }, - "execution_count": 1, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -270,13 +270,21 @@ " # Modify your existing code here\n", " \n", " '''checks if two strings are anagrams, with an option to select case sensitivity'''\n", + " \n", + " \n", " if type (word_a) == type (word_b) == str:\n", " if len (word_a) == len (word_b):\n", - " if is_case_sensitive == False:\n", - " sorted (word_a.lower()) == sorted (word_b.lower())\n", - " return True\n", - " else: \n", - " sorted (word_a) != sorted (word_b)\n", + " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", + " if is_case_sensitive == False:\n", + " return True\n", + " else:\n", + " return False\n", + " elif sorted (word_a) != sorted (word_b):\n", + " if is_case_sensitive == True:\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", " return False\n", " else: \n", " return False\n", @@ -290,7 +298,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -299,7 +307,7 @@ "False" ] }, - "execution_count": 2, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -310,7 +318,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -319,7 +327,7 @@ "False" ] }, - "execution_count": 3, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -330,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -339,7 +347,7 @@ "True" ] }, - "execution_count": 13, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -350,7 +358,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -359,7 +367,7 @@ "False" ] }, - "execution_count": 6, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -370,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -379,7 +387,7 @@ "True" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -390,7 +398,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -399,7 +407,7 @@ "True" ] }, - "execution_count": 5, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -408,6 +416,26 @@ "anagram_checker (\"tiMe\", \"miTe\", False)" ] }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"Cat\", \"Act\", True )" + ] + }, { "cell_type": "markdown", "metadata": {}, From 4e67a1d35655a3f9d5fe4876163f015eadf2f068 Mon Sep 17 00:00:00 2001 From: Ofir Date: Thu, 30 Oct 2025 00:26:09 -0400 Subject: [PATCH 6/6] I hope that now it is okay. I have also refined part 1, and added detailed explanations. Thank you for all the help, I have learned a lot! --- 02_activities/assignments/assignment_1.ipynb | 323 +++++++++++++++---- 1 file changed, 261 insertions(+), 62 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index ba2510f0b..727f5fdac 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 1, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -77,22 +77,20 @@ " \n", " '''checks if two strings are anagrams'''\n", " if type (word_a) == type (word_b) == str:\n", - " if len (word_a) == len (word_b):\n", - " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", - " return True\n", - " else:\n", - " return False\n", + " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", + " return True\n", " else:\n", " return False\n", " else:\n", - " return False\n", + " return \"invalid value\"\n", "\n", "\n", "#explanation: \n", "# The first conditional ensures that the data type is a string, allowing for the use of string methods on the data.\n", - "# The second conditional aims to determine if the length of the string referred to by the parameter \"word_a\" is equal to that referred to by \"word_b\".\n", - "# The third conditional employs two string methods on each of the parameters. First, the \"sorted\" method breaks each string into a set comprising all its characters.\n", - "# Second, the method \"lower\" ensures that all the characters appearing in each of the strings will appear as lowercase. \n", + "# The second conditional employs a string method nested in the function \"sorted\". The string method lowcases each one of the parameters \"word a\"\n", + "# and \"word b\". The two lowcased words become the argument of the function sorted which returns them as an ordered set of charchters. The conditions derermines\n", + "# that of the two sets are identical the we have an anagram. \n", + "# I understood that the len function was redundant since the sorted function create a list [and not a set] in which identical characters are repeated\n", "\n", "\n", "# Run your code to check using the words below:\n", @@ -101,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -110,7 +108,7 @@ "False" ] }, - "execution_count": 2, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -121,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -130,7 +128,7 @@ "True" ] }, - "execution_count": 3, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -141,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -150,7 +148,7 @@ "True" ] }, - "execution_count": 4, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -161,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 51, "metadata": {}, "outputs": [ { @@ -170,7 +168,7 @@ "False" ] }, - "execution_count": 5, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -181,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 52, "metadata": {}, "outputs": [ { @@ -190,7 +188,7 @@ "True" ] }, - "execution_count": 6, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -201,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -210,7 +208,7 @@ "True" ] }, - "execution_count": 7, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -221,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 54, "metadata": {}, "outputs": [ { @@ -230,7 +228,7 @@ "False" ] }, - "execution_count": 8, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -239,6 +237,26 @@ "anagram_checker (\"ofif\", \"fif\")" ] }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'invalid value'" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (55, 55)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -250,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -259,7 +277,7 @@ "True" ] }, - "execution_count": 10, + "execution_count": 116, "metadata": {}, "output_type": "execute_result" } @@ -273,32 +291,33 @@ " \n", " \n", " if type (word_a) == type (word_b) == str:\n", - " if len (word_a) == len (word_b):\n", - " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", - " if is_case_sensitive == False:\n", - " return True\n", - " else:\n", - " return False\n", - " elif sorted (word_a) != sorted (word_b):\n", - " if is_case_sensitive == True:\n", - " return True\n", - " else:\n", - " return False\n", - " else:\n", - " return False\n", - " else: \n", + " if is_case_sensitive == False:\n", + " if sorted (word_a.lower()) == sorted (word_b.lower()):\n", + " return True\n", + " else:\n", " return False\n", + " elif is_case_sensitive == True:\n", + " if sorted (word_a) != sorted (word_b):\n", + " return False\n", + " else:\n", + " return True\n", + " else:\n", + " return \"invalid value\"\n", " else:\n", - " return False\n", + " return \"invalid value\"\n", "\n", + "# explanation: \n", + "# in this part I expanded on part 1 to chec case sensativity. The code between lines 3-6 is the same as in part 1 where the function is not asked to check \n", + "# for case sensitivity. When the function is asked to check for ase sensitivity, I nested the condition in which when the function \"sorted()\" without the lower\n", + "# method returns two different strings the function of anagaram checker returns \"False\", otherwise, it returns \"True\". I also added contidions for invalid values and tested them\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker(\"Silent\", \"Listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 118, "metadata": {}, "outputs": [ { @@ -307,18 +326,38 @@ "False" ] }, - "execution_count": 11, + "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "anagram_checker(\"Silent\", \"listen\", True) # False" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"liSten\", True)" + ] + }, + { + "cell_type": "code", + "execution_count": 121, "metadata": {}, "outputs": [ { @@ -327,7 +366,7 @@ "False" ] }, - "execution_count": 13, + "execution_count": 121, "metadata": {}, "output_type": "execute_result" } @@ -338,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 122, "metadata": {}, "outputs": [ { @@ -347,7 +386,7 @@ "True" ] }, - "execution_count": 14, + "execution_count": 122, "metadata": {}, "output_type": "execute_result" } @@ -358,47 +397,47 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 123, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "False" + "True" ] }, - "execution_count": 15, + "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "anagram_checker (\"erased\", \"Sedrea\", True)\n" + "anagram_checker (\"mate\", \"Tame\", False)" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 124, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "True" + "False" ] }, - "execution_count": 16, + "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "anagram_checker (\"mate\", \"Tame\", False)" + "anagram_checker (\"tiMe\", \"miTe\", True)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 125, "metadata": {}, "outputs": [ { @@ -407,7 +446,7 @@ "True" ] }, - "execution_count": 19, + "execution_count": 125, "metadata": {}, "output_type": "execute_result" } @@ -418,7 +457,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 126, "metadata": {}, "outputs": [ { @@ -427,7 +466,7 @@ "False" ] }, - "execution_count": 20, + "execution_count": 126, "metadata": {}, "output_type": "execute_result" } @@ -436,6 +475,166 @@ "anagram_checker (\"Cat\", \"Act\", True )" ] }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 137, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker ('Act', 'Act', True)" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'invalid value'" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker ([1, 2, 3], [\"one\", \"two\", \"three\"], False)" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'invalid value'" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"love\", \"LOVE\", \"False\")" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"make\", \"made\", False)" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker (\"make\", \"made\", True)" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker ('ten', 'TEN', False)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker ('ten', 'TEN', True)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker ('Ten', 'Ten', True)" + ] + }, { "cell_type": "markdown", "metadata": {},