From 46683076fb5e3a48b1025b467636c506d769bffa Mon Sep 17 00:00:00 2001 From: TJ Lamba Date: Sat, 4 May 2024 12:02:42 -0400 Subject: [PATCH] assignment-1 --- 02_assignments/assignment_1.ipynb | 120 ++++++++++++++++++++++++------ 1 file changed, 97 insertions(+), 23 deletions(-) diff --git a/02_assignments/assignment_1.ipynb b/02_assignments/assignment_1.ipynb index 946889317..992c0ccf2 100644 --- a/02_assignments/assignment_1.ipynb +++ b/02_assignments/assignment_1.ipynb @@ -26,8 +26,8 @@ " * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n", "\n", "Checklist:\n", - "- [ ] Created a branch with the correct naming convention.\n", - "- [ ] Ensured that the repository is public.\n", + "- [x ] Created a branch with the correct naming convention.\n", + "- [x ] Ensured that the repository is public.\n", "- [ ] Reviewed the PR description guidelines and adhered to them.\n", "- [ ] Verify that the link is accessible in a private browser window.\n", "\n", @@ -56,13 +56,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 1, + "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", + "\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " #convert both words to lowercase and remove spaces\n", + " word_a = word_a.lower().replace(\" \", \"\")\n", + " word_b = word_b.lower().replace(\" \", \"\")\n", + "\n", + " #sort the char in each string\n", + " sorted_word_a = sorted(word_a)\n", + " sorted_word_b = sorted(word_b)\n", + "\n", + " #check if te sorted strings are equal\n", + " if sorted_word_a == sorted_word_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\")" @@ -70,22 +95,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Slient\", \"Night\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "anagram_checker(\"night\", \"Thing\")" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -97,26 +124,73 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", "\n", - "# Run your code to check using the words below:\n", - "anagram_checker(\"Slient\", \"listen\", False) # True" + " # Convert both strings to lowercase if case sensitivity is not required\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " \n", + " # Remove spaces from the words\n", + " word_a = word_a.replace(\" \", \"\")\n", + " word_b = word_b.replace(\" \", \"\")\n", + " \n", + " # Sort the characters in each word\n", + " sorted_word_a = sorted(word_a)\n", + " sorted_word_b = sorted(word_b)\n", + " \n", + " # Check if the sorted words are equal\n", + " if sorted_word_a == sorted_word_b:\n", + " return True\n", + " else:\n", + " return False\n", + " " ] }, { "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(\"Slient\", \"Listen\", True) # False" ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Slient\", \"Listen\", False) # True" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -144,7 +218,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4,