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
203 changes: 203 additions & 0 deletions python-env/Assignment_1_AJNC.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2150f740",
"metadata": {},
"source": [
"Part 1: Building the base Anagram Checker"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d03114a0",
"metadata": {},
"outputs": [],
"source": [
"# For testing purposes, we will write our code in the function\n",
"def anagram_checker(word_a, word_b):\n",
" if sorted(word_a.lower()) == sorted(word_b.lower()): #I made the words lowercase and ordered them alphabetically to see if they match\n",
" return True\n",
" else:\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "9fb548cc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"listen\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "65bb341a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "6ab49975",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"anagram_checker(\"night\", \"Thing\")"
]
},
{
"cell_type": "markdown",
"id": "46743fd0",
"metadata": {},
"source": [
"Part 2: Expanding the functionality of the Anagram Checker\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "d754360e",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def anagram_checker_S(word_a, word_b, is_case_sensitive):\n",
" if not is_case_sensitive: #if is sensitive is false, it is converted to lowercase \n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
" if sorted(word_a) == sorted(word_b): #ordered them alphabetically\n",
" return True\n",
" else:\n",
" return False "
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "4e539e5d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker_S(\"Silent\", \"listen\", False)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "f914b000",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker_S(\"Silent\", \"listen\", True) "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "d86c0703",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"anagram_checker_S(\"Silent\", \"Listen\", True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}