Skip to content
Open
Changes from 1 commit
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
107 changes: 97 additions & 10 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,77 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"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",
" #lower method will convert the word_a and word_b to the lowercase.\n",
" #Stored the lowercase values again to the original parameter variables because strings are immutable.\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower() \n",
" \n",
" #Sorted function will sort both words so that anagram_checker shows True when all the \n",
" #characters of both words are matached.\n",
" sort_a = sorted(word_a)\n",
" sort_b = sorted(word_b)\n",
"\n",
" #Comparing the sorted words with each other and assigning it to a new variable.\n",
" anagram_result = sort_a == sort_b\n",
"\n",
" #This returns the boolean result of the comparison.\n",
" return anagram_result\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -99,20 +146,60 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''is_case_sensitive parameter will take True or False values'''\n",
"\n",
" #When False argument is passed for is_case_sensitive, the if statement will trigger and then the characters\n",
" # of both words will converted to lower case.\n",
" if not is_case_sensitive:\n",
" word_a = word_a.lower() \n",
" word_b = word_b.lower()\n",
"\n",
" #Sorted function will sort both words so that anagram_checker shows True when all the \n",
" #characters of both words are matached.\n",
" sort_a = sorted(word_a)\n",
" sort_b = sorted(word_b)\n",
"\n",
" #Comparing the sorted words with each other and assigning it to a new variable.\n",
" anagram_result = sort_a == sort_b\n",
"\n",
" #This returns the boolean result of the comparison.\n",
" return anagram_result\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": 26,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
]
Expand All @@ -130,7 +217,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "new-learner",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -144,7 +231,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down