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
149 changes: 138 additions & 11 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,88 @@
},
{
"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",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
" '''This function checks if two valid strings are anagrams of each other'''\n",
" \n",
" # Setting the variable check as True to be used later in boolean operations\n",
" check = True\n",
" \n",
" # Evaluating if the two strings are the same size otherwise they couldn't be anagrams\n",
" if len(word_a) != len(word_b):\n",
" return False\n",
" \n",
" # Checking if the two words share the same letters\n",
" else:\n",
" for i in range(len(word_a)):\n",
" letter = word_a[i].lower()\n",
" checking = letter in word_b.lower()\n",
"\n",
" # Using the boolean operator AND to evaluate if at least one of the letters does not match\n",
" check = check and checking\n",
" \n",
" # Deciding the final output\n",
" if check == True:\n",
" return True\n",
" else:\n",
" return False\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,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
Expand All @@ -97,22 +153,93 @@
},
{
"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": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" '''This function checks if two valid strings are anagrams of each other'''\n",
" \n",
" # Setting the variable check as True to be used later in boolean operations\n",
" check = True\n",
"\n",
" # Adding the boolean option is_case_sensitive to check for case sensitivity deciding which block of code will be executed\n",
" if is_case_sensitive == False:\n",
"\n",
" # Evaluating if the two strings are the same size otherwise they couldn't be anagrams\n",
" if len(word_a) != len(word_b):\n",
" return False\n",
" \n",
" # Checking if the two words share the same letters\n",
" else:\n",
" for i in range(len(word_a)):\n",
" letter = word_a[i].lower()\n",
" checking = letter in word_b.lower()\n",
"\n",
" # Using the boolean operator AND to evaluate if at least one of the letters does not match\n",
" check = check and checking\n",
" \n",
" # Deciding the final output\n",
" if check == True:\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
" # Adding the modified block of code without the lower() string method for case sensitivity\n",
" else:\n",
" \n",
" # Evaluating if the two strings are the same size otherwise they couldn't be anagrams\n",
" if len(word_a) != len(word_b):\n",
" return False\n",
" \n",
" # Checking if the two words share the same letters\n",
" else:\n",
" for i in range(len(word_a)):\n",
" letter = word_a[i]\n",
" checking = letter in word_b\n",
"\n",
" # Using the boolean operator AND to evaluate if at least one of the letters does not match\n",
" check = check and checking\n",
" \n",
" # Deciding the final output\n",
" if check == True:\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\", False) # True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
]
Expand Down Expand Up @@ -144,7 +271,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down