diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 625be024..7931e056 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -63,6 +63,14 @@ "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", " # Your code here\n", + " first_word = word_a.lower()\n", + " second_word = word_b.lower()\n", + " if sorted(first_word) == sorted(second_word): # sorted() rearranges the letters of each word in alphabetical order. so here we can check after sorting it if both are equal to see if they are anagram\n", + " print(\"this is anagram\")\n", + " return True\n", + " else:\n", + " print(\"this is not anagram\")\n", + " return False \n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -101,9 +109,14 @@ "metadata": {}, "outputs": [], "source": [ - "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + "def anagram_checker(word_a, word_b, is_case_sensitive): # is_case_sensitive parameter is used to control make sure there is no case difference when set to falwse snd there is case difference when set to true\n", " # Modify your existing code here\n", + " \n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", "\n", + " return sorted(word_a) == sorted(word_b)\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] @@ -126,6 +139,13 @@ "|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": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {