diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index f9a68ad9b..d1bed9f4b 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -54,6 +54,40 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "def anagram_checker(word_a, word_b):\n", + " # Normalize by converting to lowercase\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " \n", + " # Sort the characters in each word\n", + " sorted_a = sorted(word_a)\n", + " sorted_b = sorted(word_b)\n", + " \n", + " # Compare the sorted words\n", + " return sorted_a == sorted_b\n", + "\n", + "# Test cases\n", + "print(anagram_checker(\"Silent\", \"listen\")) # True\n", + "print(anagram_checker(\"Silent\", \"Night\")) # False\n", + "print(anagram_checker(\"night\", \"Thing\")) # True\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -117,6 +151,39 @@ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " # Handle case sensitivity based on the flag\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " \n", + " # Sort the characters in each word\n", + " sorted_a = sorted(word_a)\n", + " sorted_b = sorted(word_b)\n", + " \n", + " # Compare the sorted words\n", + " return sorted_a == sorted_b\n", + "\n", + "# Test cases\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # False\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -144,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.2" } }, "nbformat": 4, diff --git a/assignment_1.ipynb b/assignment_1.ipynb new file mode 100644 index 000000000..d1bed9f4b --- /dev/null +++ b/assignment_1.ipynb @@ -0,0 +1,219 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Assignment #1: Anagram Checker\n", + "\n", + "**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": [ + "## Submission Information\n", + "\n", + "🚨 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 🚨 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly.\n", + "\n", + "### Submission Parameters:\n", + "* Submission Due Date: `11:59 PM - Sept 1, 2024`\n", + "* The branch name for your repo should be: `assignment-1`\n", + "* What to submit for this assignment:\n", + " * This Jupyter Notebook (assignment_1.ipynb) should be populated and should be the only change in your pull request.\n", + "* What the pull request link should look like for this assignment: `https://github.com//python/pull/`\n", + " * 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", + "- [ ] Reviewed the PR description guidelines and adhered to them.\n", + "- [ ] Verify that the link is accessible in a private browser window.\n", + "\n", + "If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#cohort-3-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part 1: Building the base Anagram Checker\n", + "\n", + "Given two valid strings, check to see if they are anagrams of each other. If it is, return `True`, else `False`. For this part, we can assume that uppercase letters are the same as if it was a lowercase character.\n", + "\n", + "Examples of anagrams:\n", + "* Silent and Listen\n", + "* Night and Think\n", + "\n", + "Example outputs:\n", + "```python\n", + "anagram_checker(\"Silent\", \"listen\") # True\n", + "anagram_checker(\"Silent\", \"Night\") # False\n", + "anagram_checker(\"night\", \"Thing\") # True\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "def anagram_checker(word_a, word_b):\n", + " # Normalize by converting to lowercase\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " \n", + " # Sort the characters in each word\n", + " sorted_a = sorted(word_a)\n", + " sorted_b = sorted(word_b)\n", + " \n", + " # Compare the sorted words\n", + " return sorted_a == sorted_b\n", + "\n", + "# Test cases\n", + "print(anagram_checker(\"Silent\", \"listen\")) # True\n", + "print(anagram_checker(\"Silent\", \"Night\")) # False\n", + "print(anagram_checker(\"night\", \"Thing\")) # True\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "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", + "\n", + "# Run your code to check using the words below:\n", + "anagram_checker(\"Silent\", \"listen\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "anagram_checker(\"Silent\", \"Night\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "anagram_checker(\"night\", \"Thing\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part 2: Expanding the functionality of the Anagram Checker\n", + "\n", + "Using your existing and functional anagram checker, let's add a boolean option called `is_case_sensitive`, which will return `True` or `False` based on if the two compared words are anagrams and if we are checking for case sensitivity." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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(\"Silent\", \"listen\", False) # True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "anagram_checker(\"Silent\", \"Listen\", True) # False" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " # Handle case sensitivity based on the flag\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + " \n", + " # Sort the characters in each word\n", + " sorted_a = sorted(word_a)\n", + " sorted_b = sorted(word_b)\n", + " \n", + " # Compare the sorted words\n", + " return sorted_a == sorted_b\n", + "\n", + "# Test cases\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # True\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # False\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "|Criteria|Pass|Fail|\n", + "|---|---|---|\n", + "|Code Execution|All code cells execute without errors.|Any code cell produces an error upon execution.|\n", + "|Code Quality|Code is well-organized, concise, and includes necessary comments for clarity. E.g. Great use of variable names.|Code is unorganized, verbose, or lacks necessary comments. E.g. Single character variable names outside of loops.|" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "new-learner", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}