diff --git a/02_activities/ /assignment_1.ipynb b/02_activities/ /assignment_1.ipynb new file mode 100644 index 000000000..306fb996d --- /dev/null +++ b/02_activities/ /assignment_1.ipynb @@ -0,0 +1,232 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Assignment #1: Anagram Checker\n", + "\n", + "**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": [ + "## Submission Information\n", + "\n", + "馃毃 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 馃毃 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly.\n", + "\n", + "### Submission Parameters:\n", + "* Submission Due Date: `11:59 PM - May 4, 2025`\n", + "* The branch name for your repo should be: `assignment-1`\n", + "* What to submit for this assignment:\n", + " * This Jupyter Notebook (assignment_1.ipynb) should be populated and should be the only change in your pull request.\n", + "* What the pull request link should look like for this assignment: `https://github.com//python/pull/`\n", + " * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n", + "\n", + "Checklist:\n", + "- [x] Created a branch with the correct naming convention.\n", + "- [x] Ensured that the repository is public.\n", + "- [x] Reviewed the PR description guidelines and adhered to them.\n", + "- [x] Verify that the link is accessible in a private browser window.\n", + "\n", + "If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#dc-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part 1: Building the base Anagram Checker\n", + "\n", + "Given two valid strings, check to see if they are anagrams of each other. If it is, return `True`, else `False`. For this part, we can assume that uppercase letters are the same as if it was a lowercase character.\n", + "\n", + "Examples of anagrams:\n", + "* Silent and Listen\n", + "* Night and Think\n", + "\n", + "Example outputs:\n", + "```python\n", + "anagram_checker(\"Silent\", \"listen\") # True\n", + "anagram_checker(\"Silent\", \"Night\") # False\n", + "anagram_checker(\"night\", \"Thing\") # True\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# For testing purposes, we will write our code in the function\n", + "def anagram_checker(word_a, word_b):\n", + " # Fisrt, we make sure there is no capital letters\n", + " word_a_lower = word_a.lower()\n", + " word_b_lower = word_b.lower()\n", + " #print(word_a_lower, word_b_lower)\n", + " # Now we can order the letters to make the comparision easier\n", + " sorted_word_a = sorted(word_a_lower)\n", + " sorted_word_b = sorted(word_b_lower)\n", + " # print(\"sorted word a:\", sorted_word_a)\n", + " # print(\"sorted word b:\", sorted_word_b)\n", + " return sorted_word_a == sorted_word_b\n", + " # if TRUE \n", + " \n", + "\n", + "\n", + "# Run your code to check using the words below:\n", + "anagram_checker(\"Silent\", \"listen\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Night\")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"night\", \"Thing\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part 2: Expanding the functionality of the Anagram Checker\n", + "\n", + "Using your existing and functional anagram checker, let's add a boolean option called `is_case_sensitive`, which will return `True` or `False` based on if the two compared words are anagrams and if we are checking for case sensitivity." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + " # Fisrt, we make sure there is no capital letters\n", + " if not is_case_sensitive:\n", + " word_a_lower = word_a.lower()\n", + " word_b_lower = word_b.lower()\n", + " else:\n", + " word_a_lower = word_a \n", + " word_b_lower = word_b \n", + "\n", + " # Now we can order the letters to make the comparision easier\n", + " sorted_word_a = sorted(word_a_lower)\n", + " sorted_word_b = sorted(word_b_lower)\n", + " \n", + " return sorted_word_a == sorted_word_b\n", + "\n", + "\n", + "# Run your code to check using the words below:\n", + "anagram_checker(\"Silent\", \"listen\", False) # True" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Listen\", True) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "|Criteria|Pass|Fail|\n", + "|---|---|---|\n", + "|Code Execution|All code cells execute without errors.|Any code cell produces an error upon execution.|\n", + "|Code Quality|Code is well-organized, concise, and includes necessary comments for clarity. E.g. Great use of variable names.|Code is unorganized, verbose, or lacks necessary comments. E.g. Single character variable names outside of loops.|" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bd82b6b8b..4a4a1f4da 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -26,10 +26,10 @@ " * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n", "\n", "Checklist:\n", - "- [ ] Created a branch with the correct naming convention.\n", - "- [ ] Ensured that the repository is public.\n", - "- [ ] Reviewed the PR description guidelines and adhered to them.\n", - "- [ ] Verify that the link is accessible in a private browser window.\n", + "- [x] Created a branch with the correct naming convention.\n", + "- [x] Ensured that the repository is public.\n", + "- [x] Reviewed the PR description guidelines and adhered to them.\n", + "- [x] Verify that the link is accessible in a private browser window.\n", "\n", "If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#dc-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges." ] @@ -56,13 +56,39 @@ }, { "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": [ "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " # Fisrt, we make sure there is no capital letters\n", + " word_a_lower = word_a.lower()\n", + " word_b_lower = word_b.lower()\n", + " #print(word_a_lower, word_b_lower)\n", + " # Now we can order the letters to make the comparision easier\n", + " sorted_word_a = sorted(word_a_lower)\n", + " sorted_word_b = sorted(word_b_lower)\n", + " # print(\"sorted word a:\", sorted_word_a)\n", + " # print(\"sorted word b:\", sorted_word_b)\n", + " if sorted_word_a == sorted_word_b:\n", + " # if TRUE \n", + " return True;\n", + " else:\n", + " # if False\n", + " return False\n", + "\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +96,40 @@ }, { "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(\"Silent\", \"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\")" ] @@ -97,12 +145,38 @@ }, { "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", + " # Fisrt, we make sure there is no capital letters\n", + " if not is_case_sensitive:\n", + " word_a_lower = word_a.lower()\n", + " word_b_lower = word_b.lower()\n", + " else:\n", + " word_a_lower = word_a \n", + " word_b_lower = word_b \n", + "\n", + " # Now we can order the letters to make the comparision easier\n", + " sorted_word_a = sorted(word_a_lower)\n", + " sorted_word_b = sorted(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(\"Silent\", \"listen\", False) # True" @@ -110,9 +184,20 @@ }, { "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(\"Silent\", \"Listen\", True) # False" ] @@ -130,7 +215,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +229,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index b98c21c65..a392235db 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -72,31 +72,101 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "n0m48JsS-nMC" - }, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n" + ] + } + ], "source": [ + "#paths modified using ../\n", "all_paths = [\n", - " \"python/05_src/data/assignment_2_data/inflammation_01.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_02.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_03.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_04.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_05.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_06.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_07.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_08.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_09.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_10.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_11.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_12.csv\"\n", + " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_02.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_03.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_04.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_05.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_06.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_07.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_08.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_09.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_10.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_11.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_12.csv\"\n", "]\n", "\n", + "\n", "with open(all_paths[0], 'r') as f:\n", - " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " # Use the readline() or readlines() method to read the .csv file into a variable\n", + " lines = f.readlines()\n", + "\n", + " # Iterate through the variable using a for loop and print each row for inspection\n", + " for row in lines:\n", + " print(row.strip()) #" ] }, { @@ -130,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "82-bk4CBB1w4" }, @@ -144,14 +214,16 @@ "\n", " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", - " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n", + " # Calculate the mean (average) number of flare-ups for each patient\n", + " summary_values = np.mean(data, axis=ax)\n", "\n", " elif operation == 'max':\n", - " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", + " #Calculate the maximum number of flare-ups experienced by each patient\n", + " summary_values = np.max(data, axis=ax)\n", "\n", " elif operation == 'min':\n", - " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", - "\n", + " # Calculate the minimum number of flare-ups experienced by each patient\n", + " summary_values = np.min(data, axis=ax)\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", @@ -161,11 +233,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -228,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "_svDiRkdIwiT" }, @@ -251,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "LEYPM5v4JT0i" }, @@ -261,15 +341,28 @@ "\n", "def detect_problems(file_path):\n", " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", + " #obtain mean value per patient\n", + " means = patient_summary(file_path, 'mean')\n", + " #if True at least one patient has a mean inflamation scoare of 0, signaling a potential issue or anomaly in the data.\n", + " return check_zeros(means)\n", + "\n", "\n", - " return" + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", @@ -314,7 +407,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "dsi_participant", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +421,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/02_activities/homework/01_data_types.ipynb b/02_activities/homework/01_data_types.ipynb index f60123d4b..7b01bf5bd 100644 --- a/02_activities/homework/01_data_types.ipynb +++ b/02_activities/homework/01_data_types.ipynb @@ -1 +1,271 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"jNAI57ELh-I8"},"source":["# Getting Started: Python Fundamentals\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"5xeRB_0jiT5n"},"source":["### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n","\n","`8 * 2.5`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":158,"status":"ok","timestamp":1667929890889,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"C6c48sSBOUeE","outputId":"3628ffce-faf6-4d23-daff-5e09edf76541"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"4eICUfHi_Z-K"},"source":["`9 / 2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":43,"status":"ok","timestamp":1667929891449,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"QVdbNoA2OiQ_","outputId":"ab9f4fac-b1cc-4afc-cc54-10592b92abb1"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"DhrJoWbj_cNe"},"source":["`9 // -2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":39,"status":"ok","timestamp":1667929891450,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"cSsGq3r0Opx6","outputId":"13df11ef-d136-4a42-884e-be1e369aae52"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"lW4UnVfw_eYy"},"source":["`1.5 * 2 >= 7 - 3`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":34,"status":"ok","timestamp":1667929891452,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"54N6gcNPOylS","outputId":"938208fc-c4c3-4e58-dd18-b50d3acc84d8"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"5T-ytiTw-KvJ"},"source":["### 2. In which order will the expressions be evaluated.\n","\n","`6 * 3 + 7 * 4`\n","\n","\n","
\n"," Answer\n","\n"," `*` > `*` > `+` \n","
\n","\n","\n","`5 - 2 * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `**` > `*` > `-`\n","
\n","\n","`(5 - 2) * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `(-)` > `**` > `*` \n","
\n","\n","`5 + 2 >= 3 * 4`\n","\n","
\n"," Answer\n","\n"," `*` > `+` > `>=`\n","
"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMhUBNX+UP2C+YDtVSxQKBK","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jNAI57ELh-I8" + }, + "source": [ + "# Getting Started: Python Fundamentals\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5xeRB_0jiT5n" + }, + "source": [ + "### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n", + "\n", + "`8 * 2.5`" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 158, + "status": "ok", + "timestamp": 1667929890889, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "C6c48sSBOUeE", + "outputId": "3628ffce-faf6-4d23-daff-5e09edf76541" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8 is an \n", + "2.5 is an \n", + "8 * 2.5 returns a \n" + ] + } + ], + "source": [ + "# Your code here\n", + "print(\"8 is an\", type(8))\n", + "print(\"2.5 is an\", type(2.5))\n", + "print('8 * 2.5 returns a', type(8*2.5))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4eICUfHi_Z-K" + }, + "source": [ + "`9 / 2`" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 43, + "status": "ok", + "timestamp": 1667929891449, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "QVdbNoA2OiQ_", + "outputId": "ab9f4fac-b1cc-4afc-cc54-10592b92abb1" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9 is an \n", + "2 is an \n", + "9 / 2 returns a \n" + ] + } + ], + "source": [ + "print(\"9 is an\", type(9))\n", + "print(\"2 is an\", type(2))\n", + "print('9 / 2 returns a', type(9/2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DhrJoWbj_cNe" + }, + "source": [ + "`9 // -2`" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 39, + "status": "ok", + "timestamp": 1667929891450, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "cSsGq3r0Opx6", + "outputId": "13df11ef-d136-4a42-884e-be1e369aae52" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9 is an \n", + "2 is an \n", + "9 / 2 returns a \n" + ] + } + ], + "source": [ + "print(\"9 is an\", type(9))\n", + "print(\"2 is an\", type(-2))\n", + "print('9 / 2 returns a', type(9//-2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lW4UnVfw_eYy" + }, + "source": [ + "`1.5 * 2 >= 7 - 3`" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 34, + "status": "ok", + "timestamp": 1667929891452, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "54N6gcNPOylS", + "outputId": "938208fc-c4c3-4e58-dd18-b50d3acc84d8" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.5 * 2 = 3.0\n", + "7 - 3 = 4\n", + "Is 3.0 >= 4? False\n" + ] + } + ], + "source": [ + "result = 1.5 * 2 >= 7 - 3\n", + "print(f\"1.5 * 2 = {1.5 * 2}\")\n", + "print(f\"7 - 3 = {7 - 3}\")\n", + "print(f\"Is {1.5 * 2} >= {7 - 3}? {result}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5T-ytiTw-KvJ" + }, + "source": [ + "### 2. In which order will the expressions be evaluated.\n", + "\n", + "`6 * 3 + 7 * 4`\n", + "\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `*` > `+` \n", + "
\n", + "\n", + "\n", + "`5 - 2 * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `**` > `*` > `-`\n", + "
\n", + "\n", + "`(5 - 2) * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `(-)` > `**` > `*` \n", + "
\n", + "\n", + "`5 + 2 >= 3 * 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `+` > `>=`\n", + "
" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMhUBNX+UP2C+YDtVSxQKBK", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "dsi_participant", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/02_activities/homework/02_comments_and_errors.ipynb b/02_activities/homework/02_comments_and_errors.ipynb index 1a8c9dec9..f610e2e2f 100644 --- a/02_activities/homework/02_comments_and_errors.ipynb +++ b/02_activities/homework/02_comments_and_errors.ipynb @@ -1 +1,379 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"jNAI57ELh-I8"},"source":["# Comments and Errors\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"YNjWPDWjifTe"},"source":["### 1. Which of these expressions results in an error? Why does each error occur?"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":27,"status":"ok","timestamp":1667929891453,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"o3Oc7gU9ihND","outputId":"e17b9653-fc59-4c03-8bd5-132fcc865579"},"outputs":[],"source":["((((5 * 4 ** 7))))"]},{"cell_type":"markdown","metadata":{"id":"vN_Hk0Dxirg_"},"source":["
\n"," Answer\n","\n"," Valid -- Python accepts extraneous parentheses.\n","
"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":130},"executionInfo":{"elapsed":20,"status":"error","timestamp":1667929891454,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"JIohkU67ilDf","outputId":"2d905bb6-f573-4c1c-cc95-f248e004ec4e"},"outputs":[],"source":["84 *= 0.5 / 7"]},{"cell_type":"markdown","metadata":{"id":"EoWEA9nWiuY8"},"source":["
\n"," Answer\n","\n"," Error -- Python thinks we are trying to assign a value to 84, which is an integer literal. We can't change its value!\n","
"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":160,"status":"ok","timestamp":1667929896986,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"-Qms7P2DimjG","outputId":"9cd8ca29-b3d4-4e20-aba9-ca535def67a7"},"outputs":[],"source":["(-(-(-(-5 * (4 + 3)))))"]},{"cell_type":"markdown","metadata":{"id":"FvtzD77YivYE"},"source":["
\n"," Answer\n","\n"," Answer: Valid -- The `-` negates the value in the parentheses.\n","
"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":130},"executionInfo":{"elapsed":462,"status":"error","timestamp":1667929898860,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"d3dl1pNGioZN","outputId":"0f912a63-e784-4787-f3ab-89bd9939ab2c"},"outputs":[],"source":["5 * 3 = weight"]},{"cell_type":"markdown","metadata":{"id":"SAb5BHZ0ixm1"},"source":["
\n"," Answer\n","\n"," Error -- We cannot assign a value to an expression, even if `weight` had been defined.\n","
"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":140,"status":"ok","timestamp":1667929905100,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"a60xC38ziqOj","outputId":"8c79d0aa-e732-4b69-ae61-397f2e77b4e2"},"outputs":[],"source":["73 / -----------5"]},{"cell_type":"markdown","metadata":{"id":"fGDCqEGJizS-"},"source":["
\n"," Answer\n","\n"," Valid -- negatives cancel each other out.\n","
"]},{"cell_type":"markdown","metadata":{},"source":["### 2. Write a block of code to check if the value is a string. If it is, print out a message saying it is valid. Otherwise, raise an exception with a message saying the value must be a string."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["value = 6\n","\n","# Your code goes here"]},{"cell_type":"markdown","metadata":{},"source":["
\n"," Answer\n","\n"," ```python\n"," value = 6\n","\n"," if type(value) == str:\n"," print(\"It is valid!\")\n"," else:\n"," raise TypeError(\"The value must be a string!\")\n"," ```\n","
"]},{"cell_type":"markdown","metadata":{},"source":["### 3. What are the following errors?\n","\n","```python\n","arr = [1, 2, 3]\n","print(arr[3])\n","```\n","\n","
\n"," Answer\n","\n"," IndexError\n","
\n"]},{"cell_type":"markdown","metadata":{},"source":["\n","```python\n","fullName = \"Taylor Swift\"\n","print(full_name)\n","```\n","\n","
\n"," Answer\n","\n"," NameError\n","
\n"]},{"cell_type":"markdown","metadata":{},"source":["\n","```python\n","2 + '2' + 4\n","```\n","\n","
\n"," Answer\n","\n"," TypeError\n","
"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMhUBNX+UP2C+YDtVSxQKBK","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","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.5"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jNAI57ELh-I8" + }, + "source": [ + "# Comments and Errors\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YNjWPDWjifTe" + }, + "source": [ + "### 1. Which of these expressions results in an error? Why does each error occur?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 27, + "status": "ok", + "timestamp": 1667929891453, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "o3Oc7gU9ihND", + "outputId": "e17b9653-fc59-4c03-8bd5-132fcc865579" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "81920" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "((((5 * 4 ** 7))))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vN_Hk0Dxirg_" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Valid -- Python accepts extraneous parentheses.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 130 + }, + "executionInfo": { + "elapsed": 20, + "status": "error", + "timestamp": 1667929891454, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "JIohkU67ilDf", + "outputId": "2d905bb6-f573-4c1c-cc95-f248e004ec4e" + }, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "'literal' is an illegal expression for augmented assignment (868797654.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[2], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 84 *= 0.5 / 7\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m 'literal' is an illegal expression for augmented assignment\n" + ] + } + ], + "source": [ + "84 *= 0.5 / 7" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EoWEA9nWiuY8" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Error -- Python thinks we are trying to assign a value to 84, which is an integer literal. We can't change its value!\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 160, + "status": "ok", + "timestamp": 1667929896986, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "-Qms7P2DimjG", + "outputId": "9cd8ca29-b3d4-4e20-aba9-ca535def67a7" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "35" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(-(-(-(-5 * (4 + 3)))))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FvtzD77YivYE" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Answer: Valid -- The `-` negates the value in the parentheses.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 130 + }, + "executionInfo": { + "elapsed": 462, + "status": "error", + "timestamp": 1667929898860, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "d3dl1pNGioZN", + "outputId": "0f912a63-e784-4787-f3ab-89bd9939ab2c" + }, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "cannot assign to operator (3700621706.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[4], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m 5 * 3 = weight\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m cannot assign to operator\n" + ] + } + ], + "source": [ + "5 * 3 = weight" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SAb5BHZ0ixm1" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Error -- We cannot assign a value to an expression, even if `weight` had been defined.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 140, + "status": "ok", + "timestamp": 1667929905100, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "a60xC38ziqOj", + "outputId": "8c79d0aa-e732-4b69-ae61-397f2e77b4e2" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "-14.6" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "73 / -----------5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fGDCqEGJizS-" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Valid -- negatives cancel each other out.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Write a block of code to check if the value is a string. If it is, print out a message saying it is valid. Otherwise, raise an exception with a message saying the value must be a string." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "value = 6\n", + "\n", + "# Your code goes here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + " Answer\n", + "\n", + " ```python\n", + " value = 6\n", + "\n", + " if type(value) == str:\n", + " print(\"It is valid!\")\n", + " else:\n", + " raise TypeError(\"The value must be a string!\")\n", + " ```\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. What are the following errors?\n", + "\n", + "```python\n", + "arr = [1, 2, 3]\n", + "print(arr[3])\n", + "```\n", + "\n", + "
\n", + " Answer\n", + "\n", + " IndexError\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "```python\n", + "fullName = \"Taylor Swift\"\n", + "print(full_name)\n", + "```\n", + "\n", + "
\n", + " Answer\n", + "\n", + " NameError\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "```python\n", + "2 + '2' + 4\n", + "```\n", + "\n", + "
\n", + " Answer\n", + "\n", + " TypeError\n", + "
" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMhUBNX+UP2C+YDtVSxQKBK", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "dsi_participant", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/02_activities/homework/03_functions.ipynb b/02_activities/homework/03_functions.ipynb index 35ff0851f..fec7a03ee 100644 --- a/02_activities/homework/03_functions.ipynb +++ b/02_activities/homework/03_functions.ipynb @@ -1 +1,307 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"jNAI57ELh-I8"},"source":["# Functions\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"QDChISArjYWi"},"source":["### 1. Following the function design recipe, define:\n"," * a function that converts Fahrenheit into Celsius\n"," * a function that converts kilometers into miles. (Assume there are 1.6 kilometers in a mile.)"]},{"cell_type":"code","execution_count":1,"metadata":{"id":"PM5C4swdjarO"},"outputs":[{"name":"stdout","output_type":"stream","text":["37.0\n"]}],"source":["# Your code goes here\n"]},{"cell_type":"markdown","metadata":{},"source":["
\n"," Answer\n","
\n","    def fahrenheit_to_celsius(fahrenheit):\n","      celsius = (fahrenheit - 32) * 5 / 9\n","      return celsius\n","    temp_in_celsius = fahrenheit_to_celsius(98.6)\n","    print(temp_in_celsius)\n","  
\n","\n","
"]},{"cell_type":"markdown","metadata":{"id":"dzPArgv6jfJ-"},"source":["### 2. What value is printed in the below code?"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":8,"status":"ok","timestamp":1667929905248,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"SunFsOXdjhBq","outputId":"9210bf31-d0db-4f4f-d96c-69a9f693b002"},"outputs":[],"source":["answer = 3\n","\n","def answer_to_everything():\n"," '''Return the answer to life, the universe, and everything'''\n"," answer = 42\n"," return answer\n"," \n","answer_to_everything()\n","\n","print(answer)"]},{"cell_type":"markdown","metadata":{"id":"_y9cC0sZuDAZ"},"source":["
\n"," Answer\n","\n"," Answer: 3. The answer variable in our function is locally scoped -- our program cannot access the value 42 from outside of the function, including when we called print(answer).\n","\n"," Although we called answer_to_everything(), we did not assign the output to a variable.\n","
"]},{"cell_type":"markdown","metadata":{"id":"57Tr7WP5jnZe"},"source":["### 3. Complete the examples in the docstring below, then write the body of the function. You can assume `num` is always >= 0."]},{"cell_type":"code","execution_count":6,"metadata":{"id":"l3B2ojfCjqmq"},"outputs":[{"data":{"text/plain":["''"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["def repeat(string, num):\n"," ''' Return string repeated num times.\n"," >>> repeat('yes', 4)\n"," 'yesyesyesyes'\n"," >>> repeat('no', 0)\n"," # your expected output here\n"," >>> repeat('yesnomaybe', 3)\n"," # your expected output here\n"," '''\n"," output = string*num\n"," return output\n","\n","repeat('no', 0)"]},{"cell_type":"markdown","metadata":{},"source":["
\n"," Answer\n","
\n","    from pickle import TRUE\n","    def repeat(string, num):\n","      ''' Return string repeated num times.\n","      >>> repeat('yes', 4)\n","      'yesyesyesyes'\n","      >>> repeat('no', 0)\n","      >>> repeat('yesnomaybe', 3)\n","      yesnomaybeyesnomaybeyesnomaybe\n","      '''\n","      output = string*num\n","      return output\n","  
\n","\n","
"]},{"cell_type":"markdown","metadata":{"id":"1hXddQH1jtO5"},"source":["### 4. Complete the function below. You can assume that `number` will always be a string with 10 digits and that the first 3 digits will always be the area code."]},{"cell_type":"code","execution_count":5,"metadata":{"id":"hcACgOltjs9r"},"outputs":[],"source":["from pickle import TRUE\n","def is_416_number(number):\n"," ''' Check whether the number has a 416 area code.\n"," >>> is_416_number('(416)-555-5555')\n"," True\n"," >>> is_416_number('514 416 5555')\n"," False\n"," >>> is_416_number('4165554160')\n"," True\n"," '''\n"," # Your code goes here\n","\n"," "]},{"cell_type":"markdown","metadata":{},"source":["
\n"," Answer\n","
\n","    from pickle import TRUE\n","    def is_416_number(number):\n","        ''' Check whether the number has a 416 area code.\n","        >>> is_416_number('(416)-555-5555')\n","        True\n","        >>> is_416_number('514 416 5555')\n","        False\n","        >>> is_416_number('4165554160')\n","        True\n","        '''\n","        # replace parens w/ nothing\n","        number = number.replace('(', '')\n","        number = number.replace(')', '')\n","        output = number[:3] == '416'\n","        return output\n","  
\n","\n","
"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMhUBNX+UP2C+YDtVSxQKBK","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","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.9.19"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jNAI57ELh-I8" + }, + "source": [ + "# Functions\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QDChISArjYWi" + }, + "source": [ + "### 1. Following the function design recipe, define:\n", + " * a function that converts Fahrenheit into Celsius\n", + " * a function that converts kilometers into miles. (Assume there are 1.6 kilometers in a mile.)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "PM5C4swdjarO" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "37.0\n", + "111.8468146027201\n" + ] + } + ], + "source": [ + "\n", + "def fahrenheit_to_celsius(fahrenheit):\n", + " celsius = (fahrenheit - 32) * 5 / 9\n", + " return celsius\n", + "temp_in_celsius = fahrenheit_to_celsius(98.6)\n", + "print(temp_in_celsius)\n", + "\n", + "\n", + "def kilometers_to_miles(kilo):\n", + " miles = kilo/ 1.609344\n", + " return miles\n", + "miles = kilometers_to_miles(180)\n", + "print(miles)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + " Answer\n", + "
\n",
+    "    def fahrenheit_to_celsius(fahrenheit):\n",
+    "      celsius = (fahrenheit - 32) * 5 / 9\n",
+    "      return celsius\n",
+    "    temp_in_celsius = fahrenheit_to_celsius(98.6)\n",
+    "    print(temp_in_celsius)\n",
+    "  
\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dzPArgv6jfJ-" + }, + "source": [ + "### 2. What value is printed in the below code?" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 8, + "status": "ok", + "timestamp": 1667929905248, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "SunFsOXdjhBq", + "outputId": "9210bf31-d0db-4f4f-d96c-69a9f693b002" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "answer = 3\n", + "\n", + "def answer_to_everything():\n", + " '''Return the answer to life, the universe, and everything'''\n", + " answer = 42\n", + " return answer\n", + " \n", + "answer_to_everything()\n", + "\n", + "print(answer)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_y9cC0sZuDAZ" + }, + "source": [ + "
\n", + " Answer\n", + "\n", + " Answer: 3. The answer variable in our function is locally scoped -- our program cannot access the value 42 from outside of the function, including when we called print(answer).\n", + "\n", + " Although we called answer_to_everything(), we did not assign the output to a variable.\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "57Tr7WP5jnZe" + }, + "source": [ + "### 3. Complete the examples in the docstring below, then write the body of the function. You can assume `num` is always >= 0." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "l3B2ojfCjqmq" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def repeat(string, num):\n", + " ''' Return string repeated num times.\n", + " >>> repeat('yes', 4)\n", + " 'yesyesyesyes'\n", + " >>> repeat('no', 0)\n", + " # your expected output here\n", + " >>> repeat('yesnomaybe', 3)\n", + " # your expected output here\n", + " '''\n", + " output = string*num\n", + " return output\n", + "\n", + "repeat('no', 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + " Answer\n", + "
\n",
+    "    from pickle import TRUE\n",
+    "    def repeat(string, num):\n",
+    "      ''' Return string repeated num times.\n",
+    "      >>> repeat('yes', 4)\n",
+    "      'yesyesyesyes'\n",
+    "      >>> repeat('no', 0)\n",
+    "      >>> repeat('yesnomaybe', 3)\n",
+    "      yesnomaybeyesnomaybeyesnomaybe\n",
+    "      '''\n",
+    "      output = string*num\n",
+    "      return output\n",
+    "  
\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1hXddQH1jtO5" + }, + "source": [ + "### 4. Complete the function below. You can assume that `number` will always be a string with 10 digits and that the first 3 digits will always be the area code." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "hcACgOltjs9r" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from pickle import TRUE\n", + "def is_416_number(number):\n", + " ''' Check whether the number has a 416 area code.\n", + " >>> is_416_number('(416)-555-5555')\n", + " True\n", + " >>> is_416_number('514 416 5555')\n", + " False\n", + " >>> is_416_number('4165554160')\n", + " True\n", + " '''\n", + " # Your code goes here\n", + " # replace parens w/ nothing\n", + " number = number.replace('(', '')\n", + " number = number.replace(')', '')\n", + " output = number[:3] == '416'\n", + " return output\n", + "\n", + "is_416_number('4165554160')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + " Answer\n", + "
\n",
+    "    from pickle import TRUE\n",
+    "    def is_416_number(number):\n",
+    "        ''' Check whether the number has a 416 area code.\n",
+    "        >>> is_416_number('(416)-555-5555')\n",
+    "        True\n",
+    "        >>> is_416_number('514 416 5555')\n",
+    "        False\n",
+    "        >>> is_416_number('4165554160')\n",
+    "        True\n",
+    "        '''\n",
+    "        # replace parens w/ nothing\n",
+    "        number = number.replace('(', '')\n",
+    "        number = number.replace(')', '')\n",
+    "        output = number[:3] == '416'\n",
+    "        return output\n",
+    "  
\n", + "\n", + "
" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMhUBNX+UP2C+YDtVSxQKBK", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "dsi_participant", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/02_activities/homework/04_strings.ipynb b/02_activities/homework/04_strings.ipynb index 6289352ed..4c256cbbd 100644 --- a/02_activities/homework/04_strings.ipynb +++ b/02_activities/homework/04_strings.ipynb @@ -1 +1,134 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"cxCHAm0GXfFb"},"source":["# Strings\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"DbzTxpsposCe"},"source":["### 1. Write a multi-line string about anything you want and print it\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"p5sB4WjWh2Tp"},"outputs":[],"source":["# Your code goes here"]},{"cell_type":"markdown","metadata":{},"source":["### 2. Append a \"world\" to the following word."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Your code goes here"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyO3VijQCXDe7a1I0vgK92JH","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","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.5"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "cxCHAm0GXfFb" + }, + "source": [ + "# Strings\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DbzTxpsposCe" + }, + "source": [ + "### 1. Write a multi-line string about anything you want and print it\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "p5sB4WjWh2Tp" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ces贸 la horrible noche,\n", + "\n", + "La libertad sublime\n", + "\n", + "Derrama las auroras\n", + "\n", + "De su invencible luz.\n", + "\n", + "La humanidad entera,\n", + "\n", + "Que entre cadenas gime,\n", + "\n", + "Comprende las palabras\n", + "\n", + "Del que muri贸 en la cruz.\n" + ] + } + ], + "source": [ + "himn = \"\"\"Ces贸 la horrible noche,\n", + "\n", + "La libertad sublime\n", + "\n", + "Derrama las auroras\n", + "\n", + "De su invencible luz.\n", + "\n", + "La humanidad entera,\n", + "\n", + "Que entre cadenas gime,\n", + "\n", + "Comprende las palabras\n", + "\n", + "Del que muri贸 en la cruz.\"\"\"\n", + "\n", + "print(himn)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Append a \"world\" to the following word." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ces贸 ', 'Wolrd']\n" + ] + } + ], + "source": [ + "# Your code goes here\n", + "list1 = [himn[0:5]]\n", + "list1.append(\"Wolrd\")\n", + "print(list1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyO3VijQCXDe7a1I0vgK92JH", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "dsi_participant", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}