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
102 changes: 74 additions & 28 deletions 02_assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-05T05:07:00.393696Z",
"start_time": "2024-05-05T05:07:00.383070Z"
}
},
"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",
" if sorted(word_a.lower()) == sorted(word_b.lower()) :\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Slient\", \"listen\")"
]
"assert (anagram_checker(\"Slient\", \"listen\"))"
],
"outputs": [],
"execution_count": 14
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-05T05:07:09.541776Z",
"start_time": "2024-05-05T05:07:09.522139Z"
}
},
"source": "assert not anagram_checker(\"Slient\", \"Night\")",
"outputs": [],
"source": [
"anagram_checker(\"Slient\", \"Night\")"
]
"execution_count": 15
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"anagram_checker(\"night\", \"Thing\")"
]
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-05T05:07:18.008290Z",
"start_time": "2024-05-05T05:07:17.899592Z"
}
},
"source": "assert anagram_checker(\"night\", \"Thing\")",
"outputs": [
{
"ename": "AssertionError",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mAssertionError\u001B[0m Traceback (most recent call last)",
"\u001B[0;32m<ipython-input-17-73ebf159c920>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0;32massert\u001B[0m \u001B[0;32mnot\u001B[0m \u001B[0managram_checker\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"night\"\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"Thing\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m",
"\u001B[0;31mAssertionError\u001B[0m: "
]
}
],
"execution_count": 17
},
{
"cell_type": "markdown",
Expand All @@ -96,26 +122,46 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"cell_type": "markdown",
"source": ""
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-05T05:06:31.184653Z",
"start_time": "2024-05-05T05:06:31.173883Z"
}
},
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" if not is_case_sensitive:\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" if sorted(word_a) == sorted(word_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\", False) # True"
]
"assert anagram_checker(\"Slient\", \"listen\", False) # True"
],
"outputs": [],
"execution_count": 13
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-05T05:06:19.255129Z",
"start_time": "2024-05-05T05:06:19.251818Z"
}
},
"source": "assert not anagram_checker(\"Slient\", \"Listen\", True) # False",
"outputs": [],
"source": [
"anagram_checker(\"Slient\", \"Listen\", True) # False"
]
"execution_count": 12
},
{
"cell_type": "markdown",
Expand Down