Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python assignment 1 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
136 changes: 118 additions & 18 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"**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": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -56,34 +61,82 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 71,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'True'"
]
},
"execution_count": 71,
"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",
" #listing characters in word_a and word_b irrespective of capitalization by setting all letters in both words to lowercase\n",
" list_a = [char for char in word_a.lower()]\n",
" list_b = [char for char in word_b.lower()]\n",
"\n",
" #sort the lists of word_a letters and word_b letters and determine whether the contained letters are the same\n",
" list_a.sort()\n",
" list_b.sort()\n",
"\n",
" if list_a==list_b:\n",
" return \"True\"\n",
" else:\n",
" return \"False\"\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
"anagram_checker(\"Slient\", \"listen\") \n",
"\n",
"#result of code is \"True\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 72,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'False'"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Night\")"
"anagram_checker(\"Slient\", \"Night\")\n",
"#result of code is \"False\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 73,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'True'"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
"anagram_checker(\"night\", \"Thing\")\n",
"#result of code is \"True\""
]
},
{
Expand All @@ -97,24 +150,71 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 74,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'True'"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" #list_a1 and list_b1 lists characters in word_a and word_b and is case sensitive\n",
" #list_a and list_b lists characters in word_a and word_b irrespective of capitalization by setting all letters in both words to lowercase\n",
" list_a1 = [char for char in word_a]\n",
" list_b1 = [char for char in word_b]\n",
" list_a = [char for char in word_a.lower()]\n",
" list_b = [char for char in word_b.lower()]\n",
"\n",
" #sort the lists of word_a letters and word_b letters and determine whether the contained letters are the same. list_a1 and list_b1 are case sensitive.\n",
" list_a1.sort()\n",
" list_b1.sort()\n",
" list_a.sort()\n",
" list_b.sort()\n",
"\n",
" if is_case_sensitive:\n",
" if list_a1==list_b1:\n",
" return \"True\"\n",
" else:\n",
" return \"False\"\n",
" elif list_a==list_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\", False) # True"
"anagram_checker(\"Slient\", \"listen\", False) # True\n",
"\n",
"#result of code is \"True\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 75,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'False'"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
"anagram_checker(\"Slient\", \"Listen\", True) # False\n",
"#result of code is \"False\""
]
},
{
Expand Down Expand Up @@ -144,7 +244,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down