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: 148 additions & 15 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
"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": [
"# Assignment 1: Anagram Checker\n",
"**Name:** Tanveer Rouf \n",
"**Date:** October 15, 2025\n",
"\n",
"This notebook implements an Anagram Checker that can determine if two words are anagrams, with optional case sensitivity.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -56,32 +67,98 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# For testing purposes, we will write our code in the function\n",
"\n",
"# Part 1: Base Anagram Checker\n",
"\n",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
" \"\"\"\n",
" Checks if two words are anagrams of each other (case-insensitive).\n",
" \n",
" Parameters:\n",
" word_a (str): First word\n",
" word_b (str): Second word\n",
" \n",
" Returns:\n",
" bool: True if anagrams, False otherwise\n",
" \"\"\"\n",
" # Normalize to lowercase\n",
" word_a_lower = word_a.lower()\n",
" word_b_lower = word_b.lower()\n",
" \n",
" # Compare sorted letters\n",
" return sorted(word_a_lower) == sorted(word_b_lower)\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",
"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"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(\"Silent\", \"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\")"
]
Expand All @@ -97,22 +174,78 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n"
]
},
{
"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",
"# Part 2: Anagram Checker with Case Sensitivity Option\n",
"\n",
"def anagram_checker(word_a, word_b, is_case_sensitive=False):\n",
" \"\"\"\n",
" Checks if two words are anagrams of each other.\n",
" \n",
" Parameters:\n",
" word_a (str): First word\n",
" word_b (str): Second word\n",
" is_case_sensitive (bool): Whether comparison is case-sensitive\n",
" \n",
" Returns:\n",
" bool: True if anagrams, False otherwise\n",
" \"\"\"\n",
" if not is_case_sensitive:\n",
" # Normalize to lowercase if case-insensitive\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
" \n",
" # Compare sorted letters\n",
" return sorted(word_a) == sorted(word_b)\n",
"\n",
"# Test cases\n",
"print(anagram_checker(\"Silent\", \"listen\", False)) # True\n",
"print(anagram_checker(\"Silent\", \"Listen\", True)) # False\n",
"print(anagram_checker(\"night\", \"Thing\", False)) # True\n",
"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
]
},
{
"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(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +263,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +277,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.13.4"
}
},
"nbformat": 4,
Expand Down
22 changes: 22 additions & 0 deletions 02_activities/assignments/assignment_1_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Part 1: Base Anagram Checker
def anagram_checker(word_a, word_b):
word_a_lower = word_a.lower()
word_b_lower = word_b.lower()
return sorted(word_a_lower) == sorted(word_b_lower)

# Test cases for Part 1
print(anagram_checker("Silent", "listen")) # True
print(anagram_checker("Silent", "Night")) # False
print(anagram_checker("night", "Thing")) # True

# Part 2: Anagram Checker with Case Sensitivity
def anagram_checker(word_a, word_b, is_case_sensitive=False):
if not is_case_sensitive:
word_a = word_a.lower()
word_b = word_b.lower()
return sorted(word_a) == sorted(word_b)

# Test cases for Part 2
print(anagram_checker("Silent", "listen", False)) # True
print(anagram_checker("Silent", "Listen", True)) # False
print(anagram_checker("night", "Thing", False)) # True