From 2def0bc11e87fbb0c0c57f1ac5952ec253c766a4 Mon Sep 17 00:00:00 2001 From: "Monica L. Rojas-Pena" Date: Fri, 3 May 2024 15:45:46 -0400 Subject: [PATCH] Wrote the code to solve the Python assignament-1 --- 02_assignments/assignment_1.ipynb | 93 ++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 13 deletions(-) diff --git a/02_assignments/assignment_1.ipynb b/02_assignments/assignment_1.ipynb index 946889317..5185b8c2f 100644 --- a/02_assignments/assignment_1.ipynb +++ b/02_assignments/assignment_1.ipynb @@ -56,13 +56,28 @@ }, { "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": [ "# 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", + " #This convert to lower case, then organize the letters of each word alphabetically and check\n", + " if (sorted(word_a.lower()) == sorted(word_b.lower())): \n", + " return True #return True if the two words are anagrams.\n", + " else:\n", + " return False #return False if the two words are not anagrams.\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Slient\", \"listen\")" @@ -70,18 +85,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Slient\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,12 +134,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " #When is_case_sentive is False, this will convert the words to lower case then sort the words in alphabetical order\n", + " if is_case_sensitive == False:\n", + " word_a = sorted(word_a.lower())\n", + " word_b = sorted(word_b.lower())\n", + " #if is_case_sensitive is True it will just sort the words alphabetically\n", + " else:\n", + " sorted(word_a)\n", + " sorted(word_b)\n", + " return word_a == word_b\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Slient\", \"listen\", False) # True" @@ -110,9 +166,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Slient\", \"Listen\", True) # False" ] @@ -144,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.18" } }, "nbformat": 4,