diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bd82b6b8b..97f446424 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 258, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 258, + "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", + "# ignoring case sensitivity and spaces\n", + "def anagram_checker(msg1, msg2):\n", + " # strip off spaces and convert to lower case\n", + " msg1=msg1.replace(' ','').lower()\n", + " msg2 = msg2.replace(' ','').lower()\n", + " # this is not required but this will prevent right off the bat from running sorted function\n", + " ## if two words are of unequal size\n", + " if len(msg1)!=len(msg2):\n", + " return False\n", + " msg1 = sorted(msg1)\n", + " msg2 = sorted(msg2)\n", + " return msg1==msg2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,22 +91,278 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 259, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 259, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Happy path test data" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 260, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 260, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] }, + { + "cell_type": "code", + "execution_count": 261, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 261, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"evil\", \"vile\")" + ] + }, + { + "cell_type": "code", + "execution_count": 262, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 262, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"triangle\", \"integral\")" + ] + }, + { + "cell_type": "code", + "execution_count": 263, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 263, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"a gentleman\", \"elegant man\")" + ] + }, + { + "cell_type": "code", + "execution_count": 264, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 264, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"123\", \"321\")" + ] + }, + { + "cell_type": "code", + "execution_count": 265, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 265, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"!@# $%^\", \"^$# @!%\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Not happpy path test data" + ] + }, + { + "cell_type": "code", + "execution_count": 266, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 266, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"hello\", \"billion\")" + ] + }, + { + "cell_type": "code", + "execution_count": 267, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 267, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"test\", \"ttew\")" + ] + }, + { + "cell_type": "code", + "execution_count": 268, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 268, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"abc\", \"abcd\")" + ] + }, + { + "cell_type": "code", + "execution_count": 269, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 269, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Clint Eastwood\", \"Old West Acton\")" + ] + }, + { + "cell_type": "code", + "execution_count": 270, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 270, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"123\", \"124\")" + ] + }, + { + "cell_type": "code", + "execution_count": 271, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 271, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"aab\",\"abz\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -97,24 +374,138 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 272, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 272, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + "def anagram_checker_with_case(msg1, msg2, is_case_sensitive):\n", + " if not is_case_sensitive:\n", + " msg1=msg1.lower()\n", + " msg2 = msg2.lower()\n", + " #strip off spaces and convert to lower case\n", + " msg1=msg1.replace(' ','')\n", + " msg2 = msg2.replace(' ','')\n", + " #this is not required but this will prevent right off the bat from running sorted function\n", + " ##if two words are of unequal size\n", + " if len(msg1)!=len(msg2):\n", + " return False\n", + " msg1 = sorted(msg1)\n", + " msg2 = sorted(msg2)\n", + " return msg1==msg2\n", "\n", "# Run your code to check using the words below:\n", - "anagram_checker(\"Silent\", \"listen\", False) # True" + "anagram_checker_with_case(\"Silent\", \"listen\", False) # True" + ] + }, + { + "cell_type": "code", + "execution_count": 273, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 273, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Silent\", \"Listen\", True) # False" + ] + }, + { + "cell_type": "code", + "execution_count": 274, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 274, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Triangle\", \"integral\",False)" + ] + }, + { + "cell_type": "code", + "execution_count": 275, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 275, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Triangle\", \"integral\",True)" + ] + }, + { + "cell_type": "code", + "execution_count": 276, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 276, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker_with_case(\"Evil\", \"vile\",False)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 277, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 277, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "anagram_checker(\"Silent\", \"Listen\", True) # False" + "anagram_checker_with_case(\"Evil\", \"vile\",True)" ] }, { @@ -130,7 +521,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +535,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4,