Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 62 additions & 101 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
@@ -1,136 +1,97 @@
{
"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 - December 1, 2025`\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/<your_github_username>/python/pull/<pr_id>`\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 `#dc-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": null,
"metadata": {},
"outputs": [],
"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",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "cb0f0ed1",
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
"import numpy as np\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
},
{
"cell_type": "markdown",
"execution_count": 2,
"id": "53ed2e33",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n"
]
}
],
"source": [
"### Part 2: Expanding the functionality of the Anagram Checker\n",
"# Function to check if two words are anagrams\n",
"def anagram_checker(word_a, word_b):\n",
" # Convert both words to lowercase\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
" \n",
" # Sort the characters of both words and compare\n",
" return sorted(word_a) == sorted(word_b)\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."
"# Run your code to check using the words below:\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,
"execution_count": 4,
"id": "2bbe8b7f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n"
]
}
],
"source": [
"# Function to check if two words are anagrams\n",
"# Adds support for optional case sensitivity\n",
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" \"\"\"\n",
" Returns True if word_a and word_b are anagrams.\n",
" If is_case_sensitive is False, comparison ignores letter case.\n",
" \"\"\"\n",
"\n",
" # Normalize case only if case sensitivity is disabled\n",
" if not is_case_sensitive:\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" # Compare sorted characters of both words\n",
" return sorted(word_a) == sorted(word_b)\n",
"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
"print(anagram_checker(\"Silent\", \"listen\", False)) # True\n",
"print(anagram_checker(\"Silent\", \"Listen\", True)) # False\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1fc02d45",
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
},
{
"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.|"
]
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "python-env",
"language": "python",
"name": "python3"
},
Expand All @@ -144,9 +105,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 5
}
Loading