|
54 | 54 | "```" |
55 | 55 | ] |
56 | 56 | }, |
| 57 | + { |
| 58 | + "cell_type": "markdown", |
| 59 | + "metadata": {}, |
| 60 | + "source": [ |
| 61 | + "### Module: Python\n", |
| 62 | + "### Assignment: 1 \n", |
| 63 | + "### Name: Chun-Yuan Chen" |
| 64 | + ] |
| 65 | + }, |
57 | 66 | { |
58 | 67 | "cell_type": "code", |
59 | | - "execution_count": null, |
| 68 | + "execution_count": 1, |
60 | 69 | "metadata": {}, |
61 | | - "outputs": [], |
| 70 | + "outputs": [ |
| 71 | + { |
| 72 | + "data": { |
| 73 | + "text/plain": [ |
| 74 | + "True" |
| 75 | + ] |
| 76 | + }, |
| 77 | + "execution_count": 1, |
| 78 | + "metadata": {}, |
| 79 | + "output_type": "execute_result" |
| 80 | + } |
| 81 | + ], |
62 | 82 | "source": [ |
63 | 83 | "# For testing purposes, we will write our code in the function\n", |
64 | 84 | "def anagram_checker(word_a, word_b):\n", |
65 | 85 | " # Your code here\n", |
| 86 | + " \n", |
| 87 | + " word_a = word_a.replace(\" \", \"\") # CYC: I added this just to remove spaces from words/phrases, even if it is not necessary in this case.\n", |
| 88 | + " word_b = word_b.replace(\" \", \"\") # CYC: I added this just to remove spaces from words/phrases, even if it is not necessary in this case.\n", |
| 89 | + "\n", |
| 90 | + " word_a = word_a.upper()\n", |
| 91 | + " word_b = word_b.upper()\n", |
| 92 | + " \n", |
| 93 | + " return sorted(word_a) == sorted(word_b)\n", |
| 94 | + "\n", |
66 | 95 | "\n", |
67 | 96 | "# Run your code to check using the words below:\n", |
68 | 97 | "anagram_checker(\"Silent\", \"listen\")" |
69 | 98 | ] |
70 | 99 | }, |
71 | 100 | { |
72 | 101 | "cell_type": "code", |
73 | | - "execution_count": null, |
| 102 | + "execution_count": 2, |
74 | 103 | "metadata": {}, |
75 | | - "outputs": [], |
| 104 | + "outputs": [ |
| 105 | + { |
| 106 | + "data": { |
| 107 | + "text/plain": [ |
| 108 | + "False" |
| 109 | + ] |
| 110 | + }, |
| 111 | + "execution_count": 2, |
| 112 | + "metadata": {}, |
| 113 | + "output_type": "execute_result" |
| 114 | + } |
| 115 | + ], |
76 | 116 | "source": [ |
77 | 117 | "anagram_checker(\"Silent\", \"Night\")" |
78 | 118 | ] |
79 | 119 | }, |
80 | 120 | { |
81 | 121 | "cell_type": "code", |
82 | | - "execution_count": null, |
| 122 | + "execution_count": 3, |
83 | 123 | "metadata": {}, |
84 | | - "outputs": [], |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "data": { |
| 127 | + "text/plain": [ |
| 128 | + "True" |
| 129 | + ] |
| 130 | + }, |
| 131 | + "execution_count": 3, |
| 132 | + "metadata": {}, |
| 133 | + "output_type": "execute_result" |
| 134 | + } |
| 135 | + ], |
85 | 136 | "source": [ |
86 | 137 | "anagram_checker(\"night\", \"Thing\")" |
87 | 138 | ] |
|
99 | 150 | "cell_type": "code", |
100 | 151 | "execution_count": null, |
101 | 152 | "metadata": {}, |
102 | | - "outputs": [], |
| 153 | + "outputs": [ |
| 154 | + { |
| 155 | + "data": { |
| 156 | + "text/plain": [ |
| 157 | + "True" |
| 158 | + ] |
| 159 | + }, |
| 160 | + "execution_count": 4, |
| 161 | + "metadata": {}, |
| 162 | + "output_type": "execute_result" |
| 163 | + } |
| 164 | + ], |
103 | 165 | "source": [ |
104 | 166 | "def anagram_checker(word_a, word_b, is_case_sensitive):\n", |
105 | 167 | " # Modify your existing code here\n", |
| 168 | + " \n", |
| 169 | + " word_a = word_a.replace(\" \", \"\")\n", |
| 170 | + " word_b = word_b.replace(\" \", \"\")\n", |
| 171 | + " \n", |
| 172 | + " if is_case_sensitive == True:\n", |
| 173 | + " word_a = word_a # CYC: This line might be a bit redundant in some applications, but I keep it in to make each step clearer for myself.\n", |
| 174 | + " word_b = word_b # CYC: This line might be a bit redundant in some applications, but I keep it in to make each step clearer for myself.\n", |
| 175 | + " \n", |
| 176 | + " else:\n", |
| 177 | + " word_a = word_a.upper()\n", |
| 178 | + " word_b = word_b.upper()\n", |
| 179 | + "\n", |
| 180 | + " return sorted(word_a) == sorted(word_b)\n", |
| 181 | + "\n", |
106 | 182 | "\n", |
107 | 183 | "# Run your code to check using the words below:\n", |
108 | 184 | "anagram_checker(\"Silent\", \"listen\", False) # True" |
109 | 185 | ] |
110 | 186 | }, |
111 | 187 | { |
112 | 188 | "cell_type": "code", |
113 | | - "execution_count": null, |
| 189 | + "execution_count": 5, |
114 | 190 | "metadata": {}, |
115 | | - "outputs": [], |
| 191 | + "outputs": [ |
| 192 | + { |
| 193 | + "data": { |
| 194 | + "text/plain": [ |
| 195 | + "False" |
| 196 | + ] |
| 197 | + }, |
| 198 | + "execution_count": 5, |
| 199 | + "metadata": {}, |
| 200 | + "output_type": "execute_result" |
| 201 | + } |
| 202 | + ], |
116 | 203 | "source": [ |
117 | 204 | "anagram_checker(\"Silent\", \"Listen\", True) # False" |
118 | 205 | ] |
|
130 | 217 | ], |
131 | 218 | "metadata": { |
132 | 219 | "kernelspec": { |
133 | | - "display_name": "new-learner", |
| 220 | + "display_name": "dsi_participant", |
134 | 221 | "language": "python", |
135 | 222 | "name": "python3" |
136 | 223 | }, |
|
144 | 231 | "name": "python", |
145 | 232 | "nbconvert_exporter": "python", |
146 | 233 | "pygments_lexer": "ipython3", |
147 | | - "version": "3.11.8" |
| 234 | + "version": "3.9.19" |
148 | 235 | } |
149 | 236 | }, |
150 | 237 | "nbformat": 4, |
|
0 commit comments