Skip to content
Open
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
120 changes: 97 additions & 23 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -56,36 +56,63 @@
},
{
"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\")"
]
},
{
"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": {},
Expand All @@ -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": {},
Expand Down Expand Up @@ -144,7 +218,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down