diff --git a/02_assignments/assignment_1.ipynb b/02_assignments/assignment_1.ipynb index 94688931..1c7eceb9 100644 --- a/02_assignments/assignment_1.ipynb +++ b/02_assignments/assignment_1.ipynb @@ -9,6 +9,11 @@ "**Background**: Anagram Checker is a program that takes two words and determines if an anagram can be made from it. If so, the program will return `true`, otherwise `false`." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -56,34 +61,82 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# This is a function, which we will learn more about next week. For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " #listing characters in word_a and word_b irrespective of capitalization by setting all letters in both words to lowercase\n", + " list_a = [char for char in word_a.lower()]\n", + " list_b = [char for char in word_b.lower()]\n", + "\n", + " #sort the lists of word_a letters and word_b letters and determine whether the contained letters are the same\n", + " list_a.sort()\n", + " list_b.sort()\n", + "\n", + " if list_a==list_b:\n", + " return \"True\"\n", + " else:\n", + " return \"False\"\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Slient\", \"listen\")" + "anagram_checker(\"Slient\", \"listen\") \n", + "\n", + "#result of code is \"True\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'False'" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Slient\", \"Night\")" + "anagram_checker(\"Slient\", \"Night\")\n", + "#result of code is \"False\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"night\", \"Thing\")" + "anagram_checker(\"night\", \"Thing\")\n", + "#result of code is \"True\"" ] }, { @@ -97,24 +150,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " #list_a1 and list_b1 lists characters in word_a and word_b and is case sensitive\n", + " #list_a and list_b lists characters in word_a and word_b irrespective of capitalization by setting all letters in both words to lowercase\n", + " list_a1 = [char for char in word_a]\n", + " list_b1 = [char for char in word_b]\n", + " list_a = [char for char in word_a.lower()]\n", + " list_b = [char for char in word_b.lower()]\n", + "\n", + " #sort the lists of word_a letters and word_b letters and determine whether the contained letters are the same. list_a1 and list_b1 are case sensitive.\n", + " list_a1.sort()\n", + " list_b1.sort()\n", + " list_a.sort()\n", + " list_b.sort()\n", + "\n", + " if is_case_sensitive:\n", + " if list_a1==list_b1:\n", + " return \"True\"\n", + " else:\n", + " return \"False\"\n", + " elif list_a==list_b:\n", + " return \"True\"\n", + " else:\n", + " return \"False\" \n", + "\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Slient\", \"listen\", False) # True" + "anagram_checker(\"Slient\", \"listen\", False) # True\n", + "\n", + "#result of code is \"True\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'False'" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Slient\", \"Listen\", True) # False" + "anagram_checker(\"Slient\", \"Listen\", True) # False\n", + "#result of code is \"False\"" ] }, { @@ -144,7 +244,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.19" } }, "nbformat": 4,