From 97992ba41bc84932b3281449c704e35cc7ef0ec3 Mon Sep 17 00:00:00 2001 From: Simon Choi Date: Mon, 20 Apr 2026 05:30:11 -0400 Subject: [PATCH 1/3] add the code for Anagram Checker --- 02_activities/assignments/assignment_1.ipynb | 126 ++++++++++++++++--- 1 file changed, 112 insertions(+), 14 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 72c8aec96..2608e08f0 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,39 @@ }, { "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": [ "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", " # Your code here\n", + " # check if the words are the same length\n", + " if len(word_a) != len(word_b):\n", + " return(False)\n", + " #return(len(word_a))\n", + " else:\n", + " # set them to lower case\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " #print(word_a)\n", + "\n", + " # alphabetical sorting apply to both words \n", + " word_a = sorted(word_a)\n", + " word_b = sorted(word_b)\n", + " #print(word_a)\n", + " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +96,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,12 +145,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", + " # check if the words are the same length\n", + " if len(word_a) != len(word_b):\n", + " return(False)\n", + " #return(len(word_a))\n", + " else:\n", + " # consider the \"is_case_sensitive\"\n", + " if not is_case_sensitive: \n", + " # set them to lower case\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " #print(word_a)\n", + "\n", + " # alphabetical sorting apply to both words \n", + " word_a = sorted(word_a)\n", + " word_b = sorted(word_b)\n", + " #print(word_a)\n", + " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" @@ -110,18 +186,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"listen\", True) # False" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -139,7 +237,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "python-env (3.11.15)", "language": "python", "name": "python3" }, @@ -153,7 +251,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.15" } }, "nbformat": 4, From a5d2bb440a0ec31df9f4e00a8a66bc666449a5f9 Mon Sep 17 00:00:00 2001 From: Simon Choi Date: Mon, 20 Apr 2026 05:56:40 -0400 Subject: [PATCH 2/3] cleanup those debug code --- 02_activities/assignments/assignment_1.ipynb | 32 +++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 2608e08f0..49de5e691 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 43, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -77,17 +77,15 @@ " # check if the words are the same length\n", " if len(word_a) != len(word_b):\n", " return(False)\n", - " #return(len(word_a))\n", + " \n", " else:\n", " # set them to lower case\n", " word_a = word_a.lower()\n", " word_b = word_b.lower()\n", - " #print(word_a)\n", - "\n", + " \n", " # alphabetical sorting apply to both words \n", " word_a = sorted(word_a)\n", " word_b = sorted(word_b)\n", - " #print(word_a)\n", " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", @@ -96,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -105,7 +103,7 @@ "False" ] }, - "execution_count": 44, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -116,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 51, "metadata": {}, "outputs": [ { @@ -125,7 +123,7 @@ "True" ] }, - "execution_count": 45, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -145,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 52, "metadata": {}, "outputs": [ { @@ -154,7 +152,7 @@ "True" ] }, - "execution_count": 46, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -165,19 +163,17 @@ " # check if the words are the same length\n", " if len(word_a) != len(word_b):\n", " return(False)\n", - " #return(len(word_a))\n", + "\n", " else:\n", " # consider the \"is_case_sensitive\"\n", " if not is_case_sensitive: \n", " # set them to lower case\n", " word_a = word_a.lower()\n", " word_b = word_b.lower()\n", - " #print(word_a)\n", - "\n", + " \n", " # alphabetical sorting apply to both words \n", " word_a = sorted(word_a)\n", " word_b = sorted(word_b)\n", - " #print(word_a)\n", " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", @@ -186,7 +182,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -195,7 +191,7 @@ "False" ] }, - "execution_count": 47, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } From ee2127a7b78fe6ebc366be3572b38455f2ac8b17 Mon Sep 17 00:00:00 2001 From: Simon Choi Date: Mon, 20 Apr 2026 22:23:43 -0400 Subject: [PATCH 3/3] add docstring --- 02_activities/assignments/assignment_1.ipynb | 47 ++++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 49de5e691..6924c2b0b 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ "True" ] }, - "execution_count": 49, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -74,6 +74,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", + " \"\"\"determine whether two stings are anagrams of each other.\n", + "\n", + " args: \n", + " word_a(str), word_b(str): two input string.\n", + " \n", + " returns:\n", + " bool: True if the inputs are anagrams, otherwise False.\n", + " \"\"\"\n", " # check if the words are the same length\n", " if len(word_a) != len(word_b):\n", " return(False)\n", @@ -89,12 +97,13 @@ " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\")" + "anagram_checker(\"Silent\", \"listen\")\n", + "#help(anagram_checker)" ] }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -103,7 +112,7 @@ "False" ] }, - "execution_count": 50, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -114,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -123,7 +132,7 @@ "True" ] }, - "execution_count": 51, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -143,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -152,7 +161,7 @@ "True" ] }, - "execution_count": 52, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -160,6 +169,15 @@ "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", " # Modify your existing code here\n", + " \"\"\"determine whether two stings are anagrams of each other.\n", + "\n", + " args: \n", + " word_a(str), word_b(str): two input string.\n", + " is_case_sensitive(bool,optional): if True, character case is considered. \n", + " \n", + " returns:\n", + " bool: True if the inputs are anagrams, otherwise False.\n", + " \"\"\"\n", " # check if the words are the same length\n", " if len(word_a) != len(word_b):\n", " return(False)\n", @@ -177,12 +195,13 @@ " return(word_a == word_b)\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker(\"Silent\", \"listen\", False) # True\n", + "#help(anagram_checker)" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -191,7 +210,7 @@ "False" ] }, - "execution_count": 53, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -202,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -211,7 +230,7 @@ "False" ] }, - "execution_count": 48, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" }