From 5736f3b72ee6b8f99a949b48b59cb8e984bb26dd Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:30:37 -0700 Subject: [PATCH 1/6] Created using Colaboratory --- .../Intro_to_Python.ipynb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb index a2563e8..01a99b2 100644 --- a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb +++ b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb @@ -76,7 +76,7 @@ "colab_type": "text" }, "source": [ - "\"Open" + "\"Open" ] }, { @@ -92,7 +92,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "n09QLpl3_Owj", + "colab_type": "text" + }, "source": [ "## 📹 Lecture Video\n", "The full lecture video on this notebook is available [here](https://www.youtube.com/watch?v=KI9uOsAuRI0)." @@ -105,7 +108,7 @@ "id": "Lk6HY8NU-a9K" }, "source": [ - "# Introduction to Python" + "# Introduction to Python :D" ] }, { From bec6e00d3ff37011315bee82994b3958f6e81342 Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Wed, 23 Sep 2020 14:41:02 -0700 Subject: [PATCH 2/6] Created using Colaboratory --- Week1-Introduction/Week_1_Survey.ipynb | 180 ++++++++++++++++--------- 1 file changed, 113 insertions(+), 67 deletions(-) diff --git a/Week1-Introduction/Week_1_Survey.ipynb b/Week1-Introduction/Week_1_Survey.ipynb index ebf6159..6b069f6 100644 --- a/Week1-Introduction/Week_1_Survey.ipynb +++ b/Week1-Introduction/Week_1_Survey.ipynb @@ -21,7 +21,7 @@ "colab_type": "text" }, "source": [ - "\"Open" + "\"Open" ] }, { @@ -58,7 +58,7 @@ "\n", "\n", "\n", - "Hi, In order to get you started with Google Co-lab we have created a simple survey that you will submit when done. The purpose of this survey is to help us improve this curriculum and cater to everyone's requirements in the class.\n", + "Hi, in order to get you started with Google Co-lab we have created a simple survey for you to submit. The purpose of this survey is to help us improve this curriculum and cater to everyone's learning experience in a virtual classroom.\n", "\n", "The survey will ask you the following:\n", "\n", @@ -77,11 +77,20 @@ "|Experience with Programming |\n", "|Experience with Python |\n", "\n", - "The first 4 questions are optional and you have the option of not answering them.\n", - "\n", + "The first 4 questions are optional. Feel free to skip those questions. \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6NxHmxBt1Al-", + "colab_type": "text" + }, + "source": [ "## Step 1\n", - "For this week you don't have to worry about the code, simply just run the tabs:\n", - "- The first cell below is a function for the survey we have created, you don't have to write or modify anything insde the code. Instead, simply just move the cursor over to ```[ ]``` and press the play sign." + "For this week you don't have to worry about understanding the code, simply just run the tabs:\n", + "- Please don't write or modify anything inside the code below. Instead, simply just move your cursor over to ```[ ]``` and press the play button." ] }, { @@ -98,10 +107,10 @@ " self_identification = str(input(\"\"\"\n", " \\nVoluntary Self-Identification *\n", " The following portion of the application is voluntary \n", - " and will not affect your progress in the course, Bit Project will use your \n", - " responses to collect data and track metrics at our organization \n", - " with respect to the Digital History Curriculum.\\n \n", - " Enter Y or N \\n\"\"\"))\n", + " and will not affect your progress in the course; Bit Project will use your \n", + " responses to collect data and track metrics \n", + " in regards to the Digital History Curriculum.\\n \n", + " Enter \"Y\" to continue with the Voluntary Self-Identification or \"N\" to skip this section. \\n\"\"\"))\n", " \n", " if self_identification == \"Y\" :\n", " \n", @@ -121,15 +130,15 @@ " student_profile.append(pronouns)\n", " \n", " ethnicity = str(input(\"\"\"\n", - " \\nRegardless of your answer to the prior question,\\n \n", - " please enter one of the following groups in which you \n", - " consider yourself to be a member:\n", + " \\nPlease input one of the following groups in which you \n", + " consider yourself to be a member of:\n", " - American Indian or Alaska Native\n", " - Asian\n", " - Black or African American\n", " - Native Hawaiian or Other Pacific Islander\n", " - White\n", " - Hispanic/Latino\n", + " - I am of multiple backgrounds. \n", " - Other\\n\"\"\"))\n", " student_profile.append(ethnicity)\n", " \n", @@ -168,7 +177,8 @@ " \\nPlease enter the Type of Degree you are currently working towards:\n", " - Bachelors\n", " - Associates\n", - " - Masters\\n\"\"\"))\n", + " - Masters\n", + " - PhD\\n\"\"\"))\n", " student_profile.append(type_of_degree)\n", " \n", " major = str(input(\"\\nPlease enter your major: \\n\"))\n", @@ -178,22 +188,28 @@ " Y for Yes\n", " N for No\\n\"\"\"))\n", " student_profile.append(experience_with_data_analysis)\n", + "\n", + " #place text box if they say yes to briefly explain type of experience\n", " \n", " experince_with_programming = str(input(\"\"\"\\nDo you have any previous experience with programming: \n", " Y for Yes\n", " N for No\\n\"\"\"))\n", " student_profile.append(experince_with_programming)\n", + "\n", + " #place text box if they say yes to briefly explain type of experience\n", " \n", " experience_with_python = str(input(\"\"\"\\nDo you have any previous experience with Python: \n", " Y for Yes\n", " N for No\\n\"\"\"))\n", " student_profile.append(experience_with_python)\n", "\n", - " print(\"Congratulations the survey is complete\")\n", + " #place text box if they say yes to briefly explain type of experience\n", + "\n", + " print(\"Congratulations! You have completed the survey.\")\n", "\n", " return student_profile" ], - "execution_count": null, + "execution_count": 14, "outputs": [] }, { @@ -204,10 +220,9 @@ }, "source": [ "## Step 2\n", - "Now that you you have run the first cell above, the next thing you will do is repeat the same step for the cell below; i.e move the cursor over to ```[ ]``` and press the play sign.\n", + "Now that you have run the first cell above, the next thing you will do is repeat the same step for the cell below; i.e move the cursor over to ```[ ]``` and press the play button.\n", "\n", - "The line below calls the ```student_survey()``` function.\n", - "Once you click on it, the survey questions will show up one by one, prompting you to enter an answer in the designated box. Once you have entered your answer simply press ```Enter```" + "Once you click on it, the survey questions will show up one by one, prompting you to enter an answer in the designated box. Once you have entered your answer simply press ```Enter``` to move on to the next question. " ] }, { @@ -217,14 +232,14 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 974 + "height": 1000 }, - "outputId": "bfb046d5-07b5-4941-8108-d8cb66bd9516" + "outputId": "8f057028-5b89-4510-9fa5-68c7915cac26" }, "source": [ "student_profile = student_survey()" ], - "execution_count": null, + "execution_count": 15, "outputs": [ { "output_type": "stream", @@ -233,25 +248,53 @@ " \n", "Voluntary Self-Identification *\n", " The following portion of the application is voluntary \n", - " and will not affect your progress in the course, Bit Project will use your \n", - " responses to collect data and track metrics at our organization \n", - " with respect to the Digital History Curriculum.\n", + " and will not affect your progress in the course; Bit Project will use your \n", + " responses to collect data and track metrics \n", + " in regards to the Digital History Curriculum.\n", " \n", - " Enter Y or N \n", - "N\n", + " Enter \"Y\" to continue with the Voluntary Self-Identification or \"N\" to skip this section. \n", + "Y\n", + "\n", + "Please enter your first name: \n", + "m2\n", + "\n", + "Please enter your last name: \n", + "nguyen\n", + "\n", + " \n", + "Preferred Pronouns:\n", + " - A pronoun not listed\n", + " - Ze/hir\n", + " - They/them/theirs\n", + " - She/her/hers\n", + " - He/him/his\n", + "she\n", + "\n", + " \n", + "Please input one of the following groups in which you \n", + " consider yourself to be a member of:\n", + " - American Indian or Alaska Native\n", + " - Asian\n", + " - Black or African American\n", + " - Native Hawaiian or Other Pacific Islander\n", + " - White\n", + " - Hispanic/Latino\n", + " - I am of multiple backgrounds. \n", + " - Other\n", + "asian\n", "\n", " \n", "Please enter your gender:\n", " M for Male\n", " F for Female\n", " O for Other\n", - "M\n", + "F\n", "\n", "Enter your age: \n", - "23\n", + "19\n", "\n", "Please enter the University you are affiliated with: \n", - "California State University, Fullerton\n", + "Davis\n", "\n", " \n", "Please enter the current academic status you belong to:\n", @@ -259,33 +302,34 @@ " - Sophomore\n", " - Junior\n", " - Senior\n", - "Junior\n", + "Sophomore\n", "\n", " \n", "Please enter the Type of Degree you are currently working towards:\n", " - Bachelors\n", " - Associates\n", " - Masters\n", - "Bachelors\n", + " - PhD\n", + "PhD\n", "\n", "Please enter your major: \n", - "Electrical Engineering\n", + "Applied Math\n", "\n", "Do you have any previous experience with data analysis: \n", " Y for Yes\n", " N for No\n", - "Y\n", + "N\n", "\n", "Do you have any previous experience with programming: \n", " Y for Yes\n", " N for No\n", - "Y\n", + "N\n", "\n", "Do you have any previous experience with Python: \n", " Y for Yes\n", " N for No\n", - "Y\n", - "Congratulations the survey is complete\n" + "N\n", + "Congratulations! You have completed the survey.\n" ], "name": "stdout" } @@ -299,9 +343,9 @@ }, "source": [ "## Step 3\n", - "Now that you have submitted the survey below you can view your answers below\n", + "Now that you have submitted the survey, you can view your answers below.\n", "\n", - "(click on ```[ ]```)" + "(Click on ```[ ]```)" ] }, { @@ -311,9 +355,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 235 + "height": 238 }, - "outputId": "3f928b87-765a-4a82-d35d-cea427a64317" + "outputId": "88f39ecd-3a5d-4cd9-8c67-5ff7d4413f35" }, "source": [ "headers = ['first_name','last_name','pronouns','ethnicity','gender','age','university','current_college_standing','type_of_degree','major','experience_with_data_analysis','experince_with_programming','experience_with_python']\n", @@ -322,24 +366,24 @@ "\n", "student_profile = [student_profile]" ], - "execution_count": null, + "execution_count": 16, "outputs": [ { "output_type": "stream", "text": [ - "first_name : N/A\n", - "last_name : N/A\n", - "pronouns : N/A\n", - "ethnicity : N/A\n", - "gender : M\n", - "age : 23\n", - "university : California State University, Fullerton\n", - "current_college_standing : Junior\n", - "type_of_degree : Bachelors\n", - "major : Electrical Engineering\n", - "experience_with_data_analysis : Y\n", - "experince_with_programming : Y\n", - "experience_with_python : Y\n" + "first_name : m2\n", + "last_name : nguyen\n", + "pronouns : she\n", + "ethnicity : asian\n", + "gender : F\n", + "age : 19\n", + "university : Davis\n", + "current_college_standing : Sophomore\n", + "type_of_degree : PhD\n", + "major : Applied Math\n", + "experience_with_data_analysis : N\n", + "experince_with_programming : N\n", + "experience_with_python : N\n" ], "name": "stdout" } @@ -353,13 +397,13 @@ }, "source": [ "## Step 4\n", - "Now that your answers are complete we will be saving them as a ```csv``` file in the cell below. CSV simply means Comma Separated Values. which is a very simple form to distinguish between columns.\n", + "Now that you have completed the survey, we will be saving your survey as a ```csv``` file below. CSV simply means Comma Separated Values, which is a very simple form to distinguish between columns.\n", "\n", - "When you run the cell, you will be asked to designate a name to file you will be making.\n", + "When you run the cell, you will be asked to input a name for the file you will be making.\n", "Follow the format \n", "```YourStudentID_WeekOne``` and press Enter.\n", "\n", - "Note: Instead of moving your cursor on the ```[ ]``` sign everytime you can simply press Shift + Enter together, which will automatically run the next cell. Try it out here" + "Tip: Instead of moving your cursor on the ```[ ]``` sign everytime you can simply press Shift + Enter together, which will automatically run the next cell. Try it out here." ] }, { @@ -369,9 +413,9 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 118 + "height": 119 }, - "outputId": "d24d65ca-ff59-477c-c9d9-a9f1ec9adbf5" + "outputId": "70701ab5-9131-4a54-e461-b7f3e935f9a7" }, "source": [ "import csv\n", @@ -392,7 +436,7 @@ " write.writerows(student_profile) \n", " file.close()" ], - "execution_count": null, + "execution_count": 17, "outputs": [ { "output_type": "stream", @@ -402,7 +446,7 @@ "Enter the name of your file\n", "Follow the following format:\n", "\"YourStudentID_WeekOne\": \n", - "0123456789_WeekOne\n" + "917003682_WeekOne\n" ], "name": "stdout" } @@ -417,8 +461,10 @@ "source": [ "## Step 5\n", "\n", - "Now that you have successfully made a ```.csv``` file (you can confirm it by clicking on the folder icon to left)\n", - "The next step is to download it to your local machine. Simply running the next cell will download you file." + "You can confirm that you have made a ```.csv``` file by clicking on the folder icon to left. \n", + "The next step is to download the file to your local machine. Simply running the next cell will download the file for you.\n", + "\n", + "(Click on ```[ ]```)" ] }, { @@ -430,13 +476,13 @@ "base_uri": "https://localhost:8080/", "height": 17 }, - "outputId": "ea09f80f-c1b1-4407-cd30-cf5d7f00f3a4" + "outputId": "09c5bb35-3782-4266-f665-dfa62fa910bf" }, "source": [ "from google.colab import files\n", "files.download(filename)" ], - "execution_count": null, + "execution_count": 18, "outputs": [ { "output_type": "display_data", @@ -496,7 +542,7 @@ "output_type": "display_data", "data": { "application/javascript": [ - "download(\"download_cd76537b-d709-4c47-a37c-efb2f1a91df2\", \"0123456789_WeekOne.csv\", 298)" + "download(\"download_ecd62a26-10c6-4a73-b6d9-a76fab115514\", \"917003682_WeekOne.csv\", 254)" ], "text/plain": [ "" From 76a4da1bda10bb1adbdbba2f3fe8d18eb2aa1e09 Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Wed, 23 Sep 2020 15:03:49 -0700 Subject: [PATCH 3/6] Created using Colaboratory --- .../Intro_to_Python.ipynb | 152 ++++++++++++++---- 1 file changed, 118 insertions(+), 34 deletions(-) diff --git a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb index 01a99b2..68e5447 100644 --- a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb +++ b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb @@ -93,7 +93,7 @@ { "cell_type": "markdown", "metadata": { - "id": "n09QLpl3_Owj", + "id": "akAeO87X6xQf", "colab_type": "text" }, "source": [ @@ -108,7 +108,7 @@ "id": "Lk6HY8NU-a9K" }, "source": [ - "# Introduction to Python :D" + "# Introduction to Python" ] }, { @@ -154,6 +154,9 @@ " - Nesting With Dictionaries\n", " - Dictionary Methods\n", " - **4.0 Now Try This**\n", + "\n", + "SPLIT NOTEBOOK HERE\n", + "\n", "- Comparison Operators\n", "- Functions\n", " - Intro to Functions\n", @@ -186,7 +189,7 @@ "source": [ "## Why, Where, and How we use Python\n", "\n", - "Python is a very popular scripting language that you can use to create applications and programs of all sizes and complexity. It is very easy to learn and has very little syntax, making it very efficient to code with. Python is also the language of choice for many when performing comprehensive data analysis. " + "Python is a very popular programming language that you can use to create applications and programs of all sizes and complexity. It is very easy to learn and write, making it very efficient to code with. Python is also the language of choice for many when performing comprehensive data analysis. " ] }, { @@ -214,7 +217,7 @@ "source": [ "## Grading\n", "\n", - "In order to work on the NTT sections and submit them for grading, you'll need to run the code block beloW. It will ask for your student ID number and then create a folder that will house your answers for each question. At the very end of the notebook, there is a code section that will download this folder as a zip file to your computer. This zip file will be your final submission." + "In order to work on the Now Try This (NTT) sections and submit them for grading, you'll need to run the code block below. It will ask for your student ID number and then create a folder that will store your answers for each question. At the very end of the notebook, there is a code section that will download this folder as a zip file to your computer. This zip file will be used as your final submission." ] }, { @@ -222,7 +225,11 @@ "metadata": { "id": "84-l3o9seILt", "colab_type": "code", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "accc5515-a27c-4ff0-85a0-b84c10ba88f1" }, "source": [ "import os\n", @@ -242,8 +249,17 @@ "else:\n", " print('Directory Already Exists')" ], - "execution_count": null, - "outputs": [] + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Please Enter your Student ID: 917003682\n", + "Successfully Created Directory, Lets get started\n" + ], + "name": "stdout" + } + ] }, { "cell_type": "markdown", @@ -276,9 +292,9 @@ "\n", "Python has various \"types\" of numbers. We'll strictly cover integers and floating point numbers for now.\n", "\n", - "Integers are just whole numbers, positive or negative. (2,4,-21,etc.)\n", + "Integers are just whole numbers, including both positive and negative. (2,4,-21,etc.)\n", "\n", - "Floating point numbers in Python have a decimal point in them, or use an exponential (e). For example 3.14 and 2.17 are *floats*. 5E7 (5 times 10 to the power of 7) is also a float. This is scientific notation and something you've probably seen in math classes.\n", + "Floating point numbers in Python have a decimal point in them, or use an exponential (e). For example 3.14 and 2.17 are *floats*. 5E7 (a.k.a. 5 times 10 to the power of 7) is also a float. This is scientific notation and something you've probably seen before in your previous math classes.\n", "\n", "Let's start working through numbers and arithmetic:" ] @@ -298,14 +314,31 @@ "metadata": { "colab_type": "code", "id": "P0fJlFvk2wVQ", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "2b1ba3eb-d96a-4572-e5e4-73f843b9e770" }, "source": [ "# Addition\n", "4+5" ], - "execution_count": null, - "outputs": [] + "execution_count": 2, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "9" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 2 + } + ] }, { "cell_type": "code", @@ -354,14 +387,31 @@ "metadata": { "colab_type": "code", "id": "DFVGzwgQ2wWH", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "639ca78b-b242-4389-a14e-6c7c67254993" }, "source": [ "# Floor Division\n", - "12//4" + "12//5" ], - "execution_count": null, - "outputs": [] + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "2" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] }, { "cell_type": "markdown", @@ -372,7 +422,7 @@ "source": [ "What happened here?\n", "\n", - "The reason we get this result is because we are using \"*floor*\" division. The // operator (two forward slashes) removes any decimals and doesn't round. This always produces an integer answer." + "The reason we get this result (2) is because we are using \"*floor*\" division. The // operator (two forward slashes) removes any decimals and doesn't round. This always produces an integer answer." ] }, { @@ -390,14 +440,32 @@ "metadata": { "colab_type": "code", "id": "zAwDlKQr2wWW", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "8aa880cc-4b2f-4c0f-b719-de826066d177" }, "source": [ "# Modulo\n", + "x = 9\n", "x % 4" ], - "execution_count": null, - "outputs": [] + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "1" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 5 + } + ] }, { "cell_type": "markdown", @@ -406,7 +474,7 @@ "id": "SmrF4pzM2wWd" }, "source": [ - "4 goes into 9 twice, with a remainder of 1. The % operator returns the remainder after division." + "4 goes into 9 twice, with a remainder of 1. The % (mod) operator returns the remainder after division." ] }, { @@ -455,7 +523,7 @@ "colab": {} }, "source": [ - "# Order of Operations\n", + "# Order of Operations (PEMDAS)\n", "4 + 20 * 52 + 5" ], "execution_count": null, @@ -484,7 +552,7 @@ "source": [ "## Variable Assignments\n", "\n", - "we can do a lot more with Python than just using it as a calculator. We can store any numbers we create in **variables**.\n", + "We can do a lot more with Python than just using it as a calculator. We can store any numbers we create in **variables**.\n", "\n", "We use a single equals sign to assign labels or values to variables. Let's see a few examples of how we can do this." ] @@ -510,7 +578,7 @@ "id": "2SZAO47P2wXY" }, "source": [ - "Now if I call *a* in my Python script, Python will treat it as the integer 10." + "Now if I call *a* in my code, Python will treat it as the integer 10." ] }, { @@ -518,14 +586,30 @@ "metadata": { "colab_type": "code", "id": "CNFrGd-m2wXa", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 181 + }, + "outputId": "da039db6-b00d-4361-dad2-054d00a146c9" }, "source": [ "# Adding the objects\n", "a+a" ], - "execution_count": null, - "outputs": [] + "execution_count": 6, + "outputs": [ + { + "output_type": "error", + "ename": "NameError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Adding the objects\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined" + ] + } + ] }, { "cell_type": "markdown", @@ -534,7 +618,7 @@ "id": "TBfuZthz2wXg" }, "source": [ - "What happens on reassignment? Will Python let us write it over?" + "What happens when we try to reassign a new value to the variable \"a\"? Will Python let us overwrite it?" ] }, { @@ -597,7 +681,7 @@ "colab": {} }, "source": [ - "# Use A to redefine A\n", + "# Use a to redefine a\n", "a = a+a" ], "execution_count": null, @@ -626,16 +710,16 @@ "source": [ "The names you use when creating these labels need to follow a few rules:\n", "\n", - " 1. Names can not start with a number.\n", - " 2. There can be no spaces in the name, use _ instead.\n", - " 3. Can't use any of these symbols :'\",<>/?|\\()!@#$%^&*~-+\n", + " 1. Names can not start with a number. (9ine)\n", + " 2. There can be no spaces in the name, use _ instead. (variable name)\n", + " 3. Can't use any of these symbols :'\",<>/?|\\()!@#$%^&*~-+ (ab?de)\n", " 4. Using lowercase names are best practice.\n", " 5. Avoid using the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), \n", " or 'I' (uppercase letter eye) as single character variable names.\n", " 6. Avoid using words that have special meaning in Python like \"list\" and \"str\"\n", "\n", "\n", - "Using variable names can be a very useful way to keep track of different variables in Python. For example:" + "Naming variables properly is a very easy way to make clear what your code is doing. For example:" ] }, { @@ -646,7 +730,7 @@ "colab": {} }, "source": [ - "# Use object names to keep better track of what's going on in your code!\n", + "# Use meaningful variable names to keep better track of what's going on in your code!\n", "income = 1000\n", "\n", "tax_rate = 0.2\n", From b881e9d1fe65491fa000d9d46081adb4eae999ae Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Wed, 23 Sep 2020 19:47:33 -0700 Subject: [PATCH 4/6] Created using Colaboratory --- .../Intro_to_Python.ipynb | 164 ++++++++++++++---- 1 file changed, 129 insertions(+), 35 deletions(-) diff --git a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb index 68e5447..9908026 100644 --- a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb +++ b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb @@ -783,7 +783,11 @@ "id": "UH3RobEsNr_4" }, "source": [ - "Strings are used in Python to record text information, such as names. Strings in Python are not treated like their own objects, but rather like a *sequence*, a consecutive series of characters. For example, Python understands the string \"hello' to be a sequence of letters in a specific order. This means we will be able to use indexing to grab particular letters (like the first letter, or the last letter).\n" + "In python, we utilize strings to represent words and phrases. For example, the following is a string \"I ate 3 cookies.\" Do note that the number 3 in this case is considered a string and not an integer. \n", + "\n", + "Strings are just one example of what we call a ***sequence*** in Python, which is a set of data in a specific order. In this case, a string is a set of letters. \n", + "\n", + "For example, Python understands the string \"hello\" is different from the string \"ehllo\". \n" ] }, { @@ -794,7 +798,7 @@ }, "source": [ "### Creating Strings\n", - "To create a string in Python you need to use either single quotes or double quotes. For example:" + "To create a string in Python, you need to use either single quotes or double quotes. For example:" ] }, { @@ -860,7 +864,7 @@ "id": "0MoF6XYPNsAJ" }, "source": [ - "The reason for the error above is because the single quote in I'm stopped the string. You can use combinations of double and single quotes to get the complete statement." + "The reason for the error above is because Python thought that the single quote in I'm marked the end of the string. Instead, you can use a combination of double and single quotes to avoid this kind of problem. " ] }, { @@ -895,7 +899,7 @@ "source": [ "### Printing Strings\n", "\n", - "Jupyter Notebooks have many neat functions that aren't available in base python. One of those is the ability to print strings by just typing it into a cell. The universal way to display strings however, is to use a **print()** function." + "Jupyter Notebooks have many neat features that aren't available in normal Python. One of those is the ability to display strings by just typing it into a cell and running it. The universal Python way to display strings, however, is to use a **print()** statement." ] }, { @@ -942,17 +946,35 @@ "metadata": { "colab_type": "code", "id": "1lSct0DqNsAZ", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + }, + "outputId": "fb480fb4-2ffd-4e0c-9ad5-274173b2ee4e" }, "source": [ "print('Hello World')\n", "print('Second string')\n", - "print('\\n prints a new line')\n", + "\n", + "# \"\\n\" prints a new line\n", "print('\\n')\n", + "\n", "print('Just to prove it to you.')" ], - "execution_count": null, - "outputs": [] + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Hello World\n", + "Second string\n", + "\n", + "\n", + "Just to prove it to you.\n" + ], + "name": "stdout" + } + ] }, { "cell_type": "markdown", @@ -961,7 +983,7 @@ "id": "gENpAoMScPl7" }, "source": [ - "Now let's move on to understanding how we can manipulate strings in our programs." + "Now let's move on to understanding how we can work with strings in our programs." ] }, { @@ -981,7 +1003,14 @@ "id": "3Ti5Nv7aNsAe" }, "source": [ - "Oftentimes, we would like to know how many characters are in a string. We can do this very easily with the **len()** function." + "Strings are made up of characters, which are anything you type. \n", + "\n", + "For example, the following is a string: \"I ate 3 cookies.\" \n", + "From this sentence, the \"I\", the \"3\", the spaces \" \", as well as the period \".\" are examples of characters. \n", + "\n", + "Oftentimes, we would like to know how many characters are in a string. \n", + "\n", + "We can do this very easily with the **len()** statement. \"len\" is short for length. " ] }, { @@ -989,13 +1018,30 @@ "metadata": { "colab_type": "code", "id": "uBNGvj9uNsAf", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "6e350fa2-0e42-4e4f-b603-8c641200fa74" }, "source": [ "len('Hello World')" ], - "execution_count": null, - "outputs": [] + "execution_count": 7, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "11" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 7 + } + ] }, { "cell_type": "markdown", @@ -1004,7 +1050,9 @@ "id": "bZonsZQnNsAi" }, "source": [ - "Python's built-in len() function counts all of the characters in the string, including spaces and punctuation." + "Python's built-in len() function counts all of the characters in the string, including spaces and punctuation.\n", + "\n", + "Note: We are utilizing the term \"function\" which will be explained in further detail later on in the course. " ] }, { @@ -1014,7 +1062,7 @@ "id": "AgTf4FqtcnD9" }, "source": [ - "Naturally, we can assign strings to variables." + "Just as we did with numbers, we can assign strings to variables." ] }, { @@ -1028,7 +1076,7 @@ "# Assign 'Hello World' to mystring variable\n", "mystring = 'Hello World'" ], - "execution_count": null, + "execution_count": 8, "outputs": [] }, { @@ -1066,7 +1114,13 @@ "id": "lk8bxjtCNsAw" }, "source": [ - "As stated before, Python treats strings as a sequence of characters. That means we can interact with each letter in a string and manipulate it. The way we access these letters is called **indexing**. Each letter has an index, which corresponds to their position in the string. In python, indices start at 0. For instance, in the string 'Hello World', 'H' has an index of 0, the 'W' has an index of 6 (because spaces count as characters), and 'd' has an index of 10. The syntax for indexing is shown below." + "As stated before, Python treats strings as a set of characters. That means we can interact with each individual letter in a string and work with it. \n", + "\n", + "The way we pick out these letters is called **indexing**. \n", + "\n", + "Imagine a line of people. Then there is a first person in line, a second, and so forth. As you are referring to these individuals by their position in line, you are indexing. You can apply this same concept to strings! \n", + "\n", + "Each letter has an index, which corresponds to their position within the string. In Python, indices start at 0. For instance, in the string 'Hello World', 'H' has an index of 0, the 'W' has an index of 6 (because spaces also count as characters), and 'd' has an index of 10. The format for indexing is shown below." ] }, { @@ -1077,7 +1131,7 @@ "colab": {} }, "source": [ - "# Extract first character in a string.\n", + "# Index first character in a string.\n", "mystring[0]" ], "execution_count": null, @@ -1116,7 +1170,7 @@ "id": "ky7Zm-NENsA7" }, "source": [ - "We can use a : to perform *slicing* which grabs everything up to a designated index. For example:" + "We can use a : to perform *slicing* which allows you to pick out multiple characters in a string at once. To do so, you specify a range of indices. For example:" ] }, { @@ -1127,7 +1181,7 @@ "colab": {} }, "source": [ - "# Grab all letters past the first letter all the way to the end of the string\n", + "# Grab all letters past the first letter all the way to the end of the string. This is a trivial example. \n", "mystring[:]" ], "execution_count": null, @@ -1152,14 +1206,34 @@ "metadata": { "colab_type": "code", "id": "f9xrirSANsBD", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "86717c0a-a18e-443f-9227-3f4aabd47cb4" }, "source": [ "# Grab everything UP TO the 5th index\n", "mystring[:5]" ], - "execution_count": null, - "outputs": [] + "execution_count": 10, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Hello'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] }, { "cell_type": "markdown", @@ -1168,22 +1242,42 @@ "id": "5dp4GDO0NsBG" }, "source": [ - "Note what happened above. We told Python to grab everything from 0 up to 5. It doesn't include the character in the 5th index. You'll notice this a lot in Python, where statements are usually in the context of \"up to, but not including\"." + "Note what happened above. We told Python to grab everything from 0 up to 5. It doesn't include the character in the 5th index (\" \"). You'll notice this a lot in Python, where statements are usually in the context of \"up to, but not including\"." ] }, { "cell_type": "code", "metadata": { + "id": "mfUzDlat-WqH", "colab_type": "code", - "id": "WfpDNfiKNsBG", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "81b3ecd9-d8b2-4295-8d76-bf74cb29bcb2" }, "source": [ - "# The whole string\n", - "mystring[:]" + "# Grab everything from \"1\" to before \"o\"\n", + "mystring[2:7]" ], - "execution_count": null, - "outputs": [] + "execution_count": 9, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'llo W'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 9 + } + ] }, { "cell_type": "markdown", @@ -1192,7 +1286,7 @@ "id": "lksAiQL6NsBK" }, "source": [ - "We don't have to go forwards. Negative indexing allows us to start from the *end* of the string and work backwards." + "We don't always have to index from the beginning to the end. Negative indexing allows us to start from the *end* of the string and work backwards." ] }, { @@ -1230,7 +1324,7 @@ "id": "XxBxY0SBNsBQ" }, "source": [ - "We can also use indexing and slicing to grab characters by a specified step size (1 is the default). See the following examples." + "We can also use indexing and slicing to skip characters by a specified amount (1 is the default step size which means we do not skip any characters). See the following examples:" ] }, { @@ -1241,7 +1335,7 @@ "colab": {} }, "source": [ - "# Grab everything, but go in steps size of 1\n", + "# Grab everything, but go in step size of 1\n", "mystring[::1]" ], "execution_count": null, @@ -1255,7 +1349,7 @@ "colab": {} }, "source": [ - "# Grab everything, but go in step sizes of 2\n", + "# Grab everything, but go in step size of 2\n", "mystring[0::2]" ], "execution_count": null, @@ -1282,7 +1376,7 @@ "id": "jPCEC_LvfRZp" }, "source": [ - "Strings have certain properties to them that affect the way we can, and cannot, interact with them." + "Strings have certain properties to them that affect the way we can, and cannot, work with them." ] }, { From 58bbd767ff08d744fca383cdbc113eaf1712ea97 Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Thu, 24 Sep 2020 19:26:33 -0700 Subject: [PATCH 5/6] Created using Colaboratory --- .../Intro_to_Python.ipynb | 336 +++++++++++++----- 1 file changed, 242 insertions(+), 94 deletions(-) diff --git a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb index 9908026..c4fdd74 100644 --- a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb +++ b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb @@ -249,7 +249,7 @@ "else:\n", " print('Directory Already Exists')" ], - "execution_count": 1, + "execution_count": null, "outputs": [ { "output_type": "stream", @@ -324,7 +324,7 @@ "# Addition\n", "4+5" ], - "execution_count": 2, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -397,7 +397,7 @@ "# Floor Division\n", "12//5" ], - "execution_count": 3, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -451,7 +451,7 @@ "x = 9\n", "x % 4" ], - "execution_count": 5, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -596,7 +596,7 @@ "# Adding the objects\n", "a+a" ], - "execution_count": 6, + "execution_count": null, "outputs": [ { "output_type": "error", @@ -961,7 +961,7 @@ "\n", "print('Just to prove it to you.')" ], - "execution_count": 6, + "execution_count": null, "outputs": [ { "output_type": "stream", @@ -1027,7 +1027,7 @@ "source": [ "len('Hello World')" ], - "execution_count": 7, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1076,7 +1076,7 @@ "# Assign 'Hello World' to mystring variable\n", "mystring = 'Hello World'" ], - "execution_count": 8, + "execution_count": 3, "outputs": [] }, { @@ -1216,7 +1216,7 @@ "# Grab everything UP TO the 5th index\n", "mystring[:5]" ], - "execution_count": 10, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1260,7 +1260,7 @@ "# Grab everything from \"1\" to before \"o\"\n", "mystring[2:7]" ], - "execution_count": 9, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1387,7 +1387,7 @@ }, "source": [ "### String Properties\n", - "It's important to note that strings are *immutable*. This means that once a string is created, the elements within it can not be changed or replaced. For example:" + "It's important to note that strings are *immutable*. This means that once a string is created, the characters within it can not be changed or replaced. For example:" ] }, { @@ -1395,27 +1395,63 @@ "metadata": { "colab_type": "code", "id": "xvPyEmYpNsBa", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "9c133349-303b-4593-de9c-1b6dc11dd50f" }, "source": [ "mystring" ], - "execution_count": null, - "outputs": [] + "execution_count": 4, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Hello World'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 4 + } + ] }, { "cell_type": "code", "metadata": { "colab_type": "code", "id": "NDk66bjZNsBc", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 181 + }, + "outputId": "13f2c1c8-c6c1-43a3-a4fa-12e48d73bcb5" }, "source": [ "# Let's try to change the first letter\n", "mystring[0] = 'a'" ], - "execution_count": null, - "outputs": [] + "execution_count": 5, + "outputs": [ + { + "output_type": "error", + "ename": "TypeError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Let's try to change the first letter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmystring\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'a'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" + ] + } + ] }, { "cell_type": "markdown", @@ -1424,9 +1460,9 @@ "id": "p_Q9e1MoNsBf" }, "source": [ - "The error tells it us to straight. Strings do not support assignment the same way other data types do.\n", + "The error tells it to us straight. Strings do not support reassignment the same way other data types do.\n", "\n", - "However, we *can* **concatenate** strings." + "However, we *can* **concatenate** strings. Concatenation is when you take two things and combine them together. " ] }, { @@ -1447,14 +1483,34 @@ "metadata": { "colab_type": "code", "id": "6MkkAvD9NsBk", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "35d8bbdb-1d0d-4179-bd22-d1a1487c232c" }, "source": [ "# Combine strings through concatenation\n", "mystring + \". It's me.\"" ], - "execution_count": null, - "outputs": [] + "execution_count": 6, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "\"Hello World. It's me.\"" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 6 + } + ] }, { "cell_type": "code", @@ -1464,7 +1520,7 @@ "colab": {} }, "source": [ - "# We can reassign mystring to a new value, however\n", + "# We can reassign mystring to have a new value. \n", "mystring = mystring + \". It's me.\"" ], "execution_count": null, @@ -1516,7 +1572,7 @@ "source": [ "letter = 'a'" ], - "execution_count": null, + "execution_count": 7, "outputs": [] }, { @@ -1524,22 +1580,32 @@ "metadata": { "colab_type": "code", "id": "9W5K-pOqNsBy", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "c43e5f57-5744-4d0f-e9aa-8f4abb63d21f" }, "source": [ "letter*20" ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "QVrhPwoGhubY" - }, - "source": [ - "We already saw how to use len(). This is an example of a built-in string method, but there are quite a few more which we will cover next." + "execution_count": 8, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'aaaaaaaaaaaaaaaaaaaa'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 8 + } ] }, { @@ -1551,13 +1617,11 @@ "source": [ "### Basic Built-in String methods\n", "\n", - "Objects in Python usually have built-in methods. These methods are functions inside the object that can perform actions or commands on the object itself.\n", + "Objects in Python usually have built-in methods. (Strings are an example of Python objects.) These methods are pre-defined ways to interact with the object, whether you modify the object itself or examine its properties. \n", "\n", - "We call methods with a period and then the method name. Methods are in the form:\n", + "We call methods with a period and then the method name. Methods are written in the form:\n", "\n", - "object.method(parameters)\n", - "\n", - "Parameters are extra arguments we can pass into the method. Don't worry if the details don't make 100% sense right now. We will be going into more depth with these later.\n", + "object.method()\n", "\n", "Here are some examples of built-in methods in strings:" ] @@ -1567,13 +1631,33 @@ "metadata": { "colab_type": "code", "id": "NoO8TSuwNsB2", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "7fb97c38-4956-4227-835e-510267a7044b" }, "source": [ "mystring" ], - "execution_count": null, - "outputs": [] + "execution_count": 9, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Hello World'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 9 + } + ] }, { "cell_type": "code", @@ -1622,14 +1706,31 @@ "metadata": { "colab_type": "code", "id": "Rr-Qqn3tNsCH", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "23962c42-9b51-4eba-8554-3819d9468493" }, "source": [ "# Split by a specific character (doesn't include the character in the resulting string)\n", "mystring.split('W')" ], - "execution_count": null, - "outputs": [] + "execution_count": 10, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['Hello ', 'orld']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] }, { "cell_type": "markdown", @@ -1650,7 +1751,7 @@ "source": [ "### Print Formatting\n", "\n", - "We can use the .format() method to inject string-formatted objects into strings\n", + "We can use the .format() method to insert a data type (integer, float, string, etc.) into a string statement by first converting it into a string. \n", "\n", "The easiest way to show this is through an example:" ] @@ -1701,7 +1802,7 @@ "id": "2jQg-dN0ZbY-" }, "source": [ - "Given the string 'Amsterdam' give an index command that returns 'd'. Enter your code in the cell below:" + "Given the string 'Amsterdam', write an index command that takes out the character 'd'. Enter your code in the cell below:" ] }, { @@ -1712,9 +1813,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", "#%%writefile -a {folder_location}/1.py\n", - "# Please note that if you uncomment and rub multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "s = 'Amsterdam'\n", "# Print out 'd' using indexing\n", @@ -1742,9 +1843,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", "#%%writefile -a {folder_location}/1.py\n", - "# Please note that if you uncomment and rub multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "s ='Amsterdam'\n", "# Reverse the string using slicing\n", @@ -1772,9 +1873,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", "#%%writefile -a {folder_location}/1.py\n", - "# Please note that if you uncomment and rub multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "s ='Amsterdam'\n", "\n", @@ -1794,7 +1895,11 @@ "source": [ "## Booleans\n", "\n", - "Python comes with *booleans* (values that are essentially binary: True or False, 1 or 0). It also has a placeholder object called None. Let's walk through a few quick examples of Booleans." + "Python comes with *booleans* (values that mean True or False, 1 or 0 respectively). \n", + "\n", + "It also has a placeholder object called None. If you do not know whether a variable is True or False yet, you can assign it to be None temporarily. \n", + "\n", + "Let's walk through a few quick examples of Booleans." ] }, { @@ -1808,7 +1913,7 @@ "# Set object to be a boolean\n", "a = True" ], - "execution_count": null, + "execution_count": 11, "outputs": [] }, { @@ -1816,14 +1921,31 @@ "metadata": { "colab_type": "code", "id": "B7BmKhMA218d", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a1bb1525-e3c9-47e1-cb85-67c48b4b3861" }, "source": [ "#Show\n", "a" ], - "execution_count": null, - "outputs": [] + "execution_count": 12, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "True" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 12 + } + ] }, { "cell_type": "markdown", @@ -1832,7 +1954,7 @@ "id": "sdZjutML218i" }, "source": [ - "We can also use comparison operators to create booleans. We'll cover comparison operators a little later." + "We can also use comparison operators to create booleans. We'll go into further detail about comparison operators a little later." ] }, { @@ -1856,7 +1978,7 @@ "id": "Q0d2MOxp218p" }, "source": [ - "We can use None as a placeholder for an object that we don't want to reassign yet:" + "We can use None as a placeholder for a variable that we don't want to assign anything to yet:" ] }, { @@ -1906,7 +2028,7 @@ "source": [ "## Lists\n", "\n", - "Earlier when discussing strings we introduced the concept of a *sequence*. Lists is the most generalized version of sequences in Python. Unlike strings, they are mutable, meaning the elements inside a list can be changed!\n", + "Earlier when discussing strings, we introduced the concept of a *sequence*. Lists are the most generalized versions of sequences in Python. Unlike strings, they are mutable, meaning the elements inside a list can be changed!\n", "\n", "Lists are constructed with brackets [] and commas separating every element in the list.\n", "\n", @@ -1931,7 +2053,7 @@ "colab": {} }, "source": [ - "# Assign a list to an variable named my_list\n", + "# Assign a list to a variable named my_list\n", "my_list = [1,2,3]" ], "execution_count": null, @@ -1967,7 +2089,7 @@ "id": "vRJ7rYkuOk_l" }, "source": [ - "Just like strings, the len() function will tell you how many items are in the sequence of the list." + "Just like strings, the len() function will tell you how many items are in the list." ] }, { @@ -1996,6 +2118,16 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": { + "id": "36AgITpA-UMi", + "colab_type": "text" + }, + "source": [ + "Lists can be indexed the same way as strings. " + ] + }, { "cell_type": "code", "metadata": { @@ -2091,7 +2223,7 @@ "id": "HpAWR1hJOlAA" }, "source": [ - "You would have to reassign the list to make the change permanent." + "You would have to reassign the list variable to make the change permanent." ] }, { @@ -2139,7 +2271,7 @@ "colab": {} }, "source": [ - "# Make the list double\n", + "# Double the list\n", "my_list * 2" ], "execution_count": null, @@ -2153,7 +2285,7 @@ "colab": {} }, "source": [ - "# Again doubling not permanent\n", + "# Again doubling is not permanent\n", "my_list" ], "execution_count": null, @@ -2178,9 +2310,7 @@ "source": [ "### Basic List Methods\n", "\n", - "If you are familiar with another programming language, you might start to draw parallels between arrays in another language and lists in Python. Lists in Python however, tend to be more flexible than arrays in other languages for two reasons: they have no fixed size (meaning we don't have to specify how big a list will be), and they have no fixed type constraint (like we've seen above).\n", - "\n", - "Let's go ahead and explore some more special methods for lists:" + "Let's go ahead and explore some special methods for lists:" ] }, { @@ -2242,7 +2372,7 @@ "id": "7CIIhCgYOlAd" }, "source": [ - "Use **pop** to \"pop off\" an item from the list. By default pop takes off the last index, but you can also specify which index to pop off. Let's see an example:" + "Use **pop** to \"pop off\" an item from the list. By default pop takes off the last item, but you can also specify which item to pop off by their index. Let's see an example:" ] }, { @@ -2253,7 +2383,7 @@ "colab": {} }, "source": [ - "# Pop off the 0 indexed item\n", + "# Pop off the item with an index of 0\n", "list1.pop(0)" ], "execution_count": null, @@ -2281,7 +2411,7 @@ "colab": {} }, "source": [ - "# Assign the popped element, remember default popped index is last element\n", + "# Store the popped element in a variable. Remember, the default is to pop off the last element.\n", "popped_item = list1.pop()" ], "execution_count": null, @@ -2321,7 +2451,7 @@ "id": "8Z-DqqQiOlAt" }, "source": [ - "It should also be noted that lists indexing will return an error if there is no element at that index. For example:" + "It should also be noted that lists indexing will return an error if there is no element at the specified index. For example:" ] }, { @@ -2344,7 +2474,7 @@ "id": "YPVuQbfQOlAx" }, "source": [ - "We can use the **sort** method and the **reverse** methods to also effect your lists:" + "We can use the **sort** method and the **reverse** method to also affect your lists:" ] }, { @@ -2374,16 +2504,25 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": { + "id": "nb_xdRuGBOdq", + "colab_type": "text" + }, + "source": [ + "Use **sort** to organize the list. In this case, it will sort in alphabetical order, but if it was a list of numbers, it will sort from smallest to largest." + ] + }, { "cell_type": "code", "metadata": { "colab_type": "code", - "id": "WskGGD9iOlA6", + "id": "g3-2LXA8OlA_", "colab": {} }, "source": [ - "# Use reverse to reverse order (this is permanent!)\n", - "new_list.reverse()" + "new_list.sort()" ], "execution_count": null, "outputs": [] @@ -2401,16 +2540,25 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": { + "id": "JHF-TOo5Bb9j", + "colab_type": "text" + }, + "source": [ + "Use **reverse** to reverse the order. Note that this is permanent! " + ] + }, { "cell_type": "code", "metadata": { "colab_type": "code", - "id": "g3-2LXA8OlA_", + "id": "WskGGD9iOlA6", "colab": {} }, "source": [ - "# Use sort to sort the list (in this case alphabetical order, but for numbers it will go ascending)\n", - "new_list.sort()" + "new_list.reverse()" ], "execution_count": null, "outputs": [] @@ -2481,7 +2629,7 @@ "id": "1CiTJaLFOlBN" }, "source": [ - "We can again use indexing to grab elements, but now there are two levels for the index. The items in the matrix object, and then the items inside that list!" + "We can again use indexing to grab elements, but now there are two levels for the index. The lists in the matrix object, and then the items inside those list!" ] }, { @@ -2492,7 +2640,7 @@ "colab": {} }, "source": [ - "# Grab first item in matrix object\n", + "# Grab first list (row) in the matrix object\n", "matrix[0]" ], "execution_count": null, @@ -2506,7 +2654,7 @@ "colab": {} }, "source": [ - "# Grab first item of the first item in the matrix object\n", + "# Grab the first item of the first list in the matrix object\n", "matrix[0][0]" ], "execution_count": null, @@ -2520,9 +2668,9 @@ }, "source": [ "### List Comprehensions\n", - "Python has an advanced feature called list comprehensions. They allow for quick construction of lists. To fully understand list comprehensions we need to understand for loops. So don't worry if you don't completely understand this section, and feel free to just skip it since we will return to this topic later.\n", + "Python has an advanced feature called list comprehensions. They allow us to quickly create lists. To fully understand list comprehensions, we need to understand `for` loops. So don't worry if you don't completely understand this section. Feel free to just skip it since we will return to this topic later.\n", "\n", - "But in case you want to know now, here are a few examples!" + "But in case you want to know now, here is an example!" ] }, { @@ -2579,7 +2727,7 @@ "id": "IKYj6iiBZbZR" }, "source": [ - "Build this list [0,0,0] using any of the shown ways." + "Build this list [0,0,0] using any of the previously shown ways." ] }, { @@ -2590,9 +2738,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/2.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run the cell multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "# Build the list\n", "answer1 = #INSERT CODE HERE\n", @@ -2619,9 +2767,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/2.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run the cell multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "answer2 = [1,2,[3,4,'hello']]\n", "answer2 = #INSERT CODE HERE\n", @@ -2648,9 +2796,9 @@ "colab": {} }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/2.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and run the cell multiple times, the program will keep adding your answer to the end of the file.\n", "\n", "answer3 = [5,3,4,6,1]\n", "answer3 = #INSERT CODE HERE\n", From 63f989ac3121c13cf158333f574da448dc9dbe62 Mon Sep 17 00:00:00 2001 From: minhtumn <56617716+minhtumn@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:02:03 -0700 Subject: [PATCH 6/6] Created using Colaboratory --- .../Intro_to_Python.ipynb | 1098 +++++------------ 1 file changed, 296 insertions(+), 802 deletions(-) diff --git a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb index c4fdd74..9a5a781 100644 --- a/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb +++ b/Week2-Introduction-to-Python-_-NumPy/Intro_to_Python.ipynb @@ -82,7 +82,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Z_1uxdh0MC4f" }, "source": [ @@ -93,8 +92,7 @@ { "cell_type": "markdown", "metadata": { - "id": "akAeO87X6xQf", - "colab_type": "text" + "id": "akAeO87X6xQf" }, "source": [ "## 📹 Lecture Video\n", @@ -104,7 +102,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Lk6HY8NU-a9K" }, "source": [ @@ -114,7 +111,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "JKIeFpiY-pJc" }, "source": [ @@ -183,7 +179,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "R7I6cGKU_S9_" }, "source": [ @@ -195,7 +190,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UE9OO2h1_2u_" }, "source": [ @@ -211,8 +205,7 @@ { "cell_type": "markdown", "metadata": { - "id": "CTXy5knVeILs", - "colab_type": "text" + "id": "CTXy5knVeILs" }, "source": [ "## Grading\n", @@ -224,12 +217,11 @@ "cell_type": "code", "metadata": { "id": "84-l3o9seILt", - "colab_type": "code", + "outputId": "accc5515-a27c-4ff0-85a0-b84c10ba88f1", "colab": { "base_uri": "https://localhost:8080/", "height": 51 - }, - "outputId": "accc5515-a27c-4ff0-85a0-b84c10ba88f1" + } }, "source": [ "import os\n", @@ -264,7 +256,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "spnIHTTIZMl8" }, "source": [ @@ -274,7 +265,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "yn56q8ie3bCK" }, "source": [ @@ -284,7 +274,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "LvQ8LBU22wVE" }, "source": [ @@ -302,7 +291,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "WlZ5c0m_2wVJ" }, "source": [ @@ -312,13 +300,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "P0fJlFvk2wVQ", + "outputId": "2b1ba3eb-d96a-4572-e5e4-73f843b9e770", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "2b1ba3eb-d96a-4572-e5e4-73f843b9e770" + } }, "source": [ "# Addition\n", @@ -343,9 +330,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "mtlYVK6b2wVj", - "colab": {} + "id": "mtlYVK6b2wVj" }, "source": [ "# Subtraction\n", @@ -357,9 +342,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "_1f4Ofza2wV7", - "colab": {} + "id": "_1f4Ofza2wV7" }, "source": [ "# Multiplication\n", @@ -371,9 +354,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "wUCF99zx2wWC", - "colab": {} + "id": "wUCF99zx2wWC" }, "source": [ "# Division\n", @@ -385,13 +366,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "DFVGzwgQ2wWH", + "outputId": "639ca78b-b242-4389-a14e-6c7c67254993", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "639ca78b-b242-4389-a14e-6c7c67254993" + } }, "source": [ "# Floor Division\n", @@ -416,7 +396,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "HKMA-ctF2wWS" }, "source": [ @@ -428,7 +407,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "k14zoZRz2wWT" }, "source": [ @@ -438,13 +416,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "zAwDlKQr2wWW", + "outputId": "8aa880cc-4b2f-4c0f-b719-de826066d177", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "8aa880cc-4b2f-4c0f-b719-de826066d177" + } }, "source": [ "# Modulo\n", @@ -470,7 +447,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "SmrF4pzM2wWd" }, "source": [ @@ -480,7 +456,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "KUGhim7_2wWe" }, "source": [ @@ -490,9 +465,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "oCuQ17sV2wWf", - "colab": {} + "id": "oCuQ17sV2wWf" }, "source": [ "# Powers\n", @@ -504,9 +477,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "zZ76i8rF2wWo", - "colab": {} + "id": "zZ76i8rF2wWo" }, "source": [ "# A way to do roots\n", @@ -518,9 +489,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "m6AynMCF2wW4", - "colab": {} + "id": "m6AynMCF2wW4" }, "source": [ "# Order of Operations (PEMDAS)\n", @@ -532,9 +501,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "bTgQF0GX2wW8", - "colab": {} + "id": "bTgQF0GX2wW8" }, "source": [ "# Can use parentheses to specify orders\n", @@ -546,7 +513,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "XSCsHC222wXP" }, "source": [ @@ -560,9 +526,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "PRjmRrLJ2wXQ", - "colab": {} + "id": "PRjmRrLJ2wXQ" }, "source": [ "# Let's create an object called \"a\" and assign it the number 10\n", @@ -574,7 +538,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "2SZAO47P2wXY" }, "source": [ @@ -584,13 +547,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "CNFrGd-m2wXa", + "outputId": "da039db6-b00d-4361-dad2-054d00a146c9", "colab": { "base_uri": "https://localhost:8080/", "height": 181 - }, - "outputId": "da039db6-b00d-4361-dad2-054d00a146c9" + } }, "source": [ "# Adding the objects\n", @@ -614,7 +576,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "TBfuZthz2wXg" }, "source": [ @@ -624,9 +585,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "IyUbGI6l2wXi", - "colab": {} + "id": "IyUbGI6l2wXi" }, "source": [ "# Reassignment\n", @@ -638,9 +597,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "TGLcpU8j2wXn", - "colab": {} + "id": "TGLcpU8j2wXn" }, "source": [ "# Check\n", @@ -652,7 +609,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "CyeKAg962wXu" }, "source": [ @@ -662,9 +618,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Rv40aCUd2wXv", - "colab": {} + "id": "Rv40aCUd2wXv" }, "source": [ "# Check\n", @@ -676,9 +630,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Ykxmc-gr2wX8", - "colab": {} + "id": "Ykxmc-gr2wX8" }, "source": [ "# Use a to redefine a\n", @@ -690,9 +642,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "kuz0ctr92wX_", - "colab": {} + "id": "kuz0ctr92wX_" }, "source": [ "# Check \n", @@ -704,7 +654,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "2cD46_8c2wYC" }, "source": [ @@ -725,9 +674,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vkyIeiFs2wYD", - "colab": {} + "id": "vkyIeiFs2wYD" }, "source": [ "# Use meaningful variable names to keep better track of what's going on in your code!\n", @@ -743,9 +690,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "2YlBECQF2wYH", - "colab": {} + "id": "2YlBECQF2wYH" }, "source": [ "# Show the result!\n", @@ -757,7 +702,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "kHJyh-qD2wYL" }, "source": [ @@ -769,7 +713,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "P3C3zJ-7Nr_3" }, "source": [ @@ -779,7 +722,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UH3RobEsNr_4" }, "source": [ @@ -793,7 +735,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "x6IrT_vuNr_5" }, "source": [ @@ -804,9 +745,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rYqOQqWwNr_6", - "colab": {} + "id": "rYqOQqWwNr_6" }, "source": [ "# A word\n", @@ -818,9 +757,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "B0h3v-fTNr__", - "colab": {} + "id": "B0h3v-fTNr__" }, "source": [ "# A phrase\n", @@ -832,9 +769,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "aqcRSHvPNsAC", - "colab": {} + "id": "aqcRSHvPNsAC" }, "source": [ "# Using double quotes\n", @@ -846,9 +781,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "mmszjr3vNsAG", - "colab": {} + "id": "mmszjr3vNsAG" }, "source": [ "# Be wary of contractions and apostrophes!\n", @@ -860,7 +793,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "0MoF6XYPNsAJ" }, "source": [ @@ -870,9 +802,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "wSVUTR4LNsAK", - "colab": {} + "id": "wSVUTR4LNsAK" }, "source": [ "\"This shouldn't cause an error now.\"" @@ -883,7 +813,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "4I_0dIPHNsAN" }, "source": [ @@ -893,7 +822,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "vfiOvQCHNsAO" }, "source": [ @@ -905,9 +833,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "pDoK1QbvNsAO", - "colab": {} + "id": "pDoK1QbvNsAO" }, "source": [ "# In Jupyter, this is all we need\n", @@ -919,9 +845,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "DArJAbvzNsAV", - "colab": {} + "id": "DArJAbvzNsAV" }, "source": [ "# But we can't print multiple strings\n", @@ -934,7 +858,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "JzKtMgFeNsAZ" }, "source": [ @@ -944,13 +867,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "1lSct0DqNsAZ", + "outputId": "fb480fb4-2ffd-4e0c-9ad5-274173b2ee4e", "colab": { "base_uri": "https://localhost:8080/", "height": 102 - }, - "outputId": "fb480fb4-2ffd-4e0c-9ad5-274173b2ee4e" + } }, "source": [ "print('Hello World')\n", @@ -979,7 +901,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "gENpAoMScPl7" }, "source": [ @@ -989,7 +910,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "5IkjMPlcNsAd" }, "source": [ @@ -999,7 +919,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "3Ti5Nv7aNsAe" }, "source": [ @@ -1016,13 +935,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "uBNGvj9uNsAf", + "outputId": "6e350fa2-0e42-4e4f-b603-8c641200fa74", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "6e350fa2-0e42-4e4f-b603-8c641200fa74" + } }, "source": [ "len('Hello World')" @@ -1046,7 +964,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "bZonsZQnNsAi" }, "source": [ @@ -1058,7 +975,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "AgTf4FqtcnD9" }, "source": [ @@ -1068,23 +984,19 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "RbYyeFrLNsAk", - "colab": {} + "id": "RbYyeFrLNsAk" }, "source": [ "# Assign 'Hello World' to mystring variable\n", "mystring = 'Hello World'" ], - "execution_count": 3, + "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "3sAvAFHzNsAp", - "colab": {} + "id": "3sAvAFHzNsAp" }, "source": [ "# Did it work?\n", @@ -1096,9 +1008,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Dda7HfhGNsAr", - "colab": {} + "id": "Dda7HfhGNsAr" }, "source": [ "# Print it to make sure\n", @@ -1110,7 +1020,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "lk8bxjtCNsAw" }, "source": [ @@ -1126,9 +1035,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Fgzo1XrCNsAx", - "colab": {} + "id": "Fgzo1XrCNsAx" }, "source": [ "# Index first character in a string.\n", @@ -1140,9 +1047,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "0kcd-9EZNsA1", - "colab": {} + "id": "0kcd-9EZNsA1" }, "source": [ "mystring[1]" @@ -1153,9 +1058,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "8M44L4hMNsA4", - "colab": {} + "id": "8M44L4hMNsA4" }, "source": [ "mystring[2]" @@ -1166,7 +1069,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "ky7Zm-NENsA7" }, "source": [ @@ -1176,9 +1078,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "jQKnWrNtNsA8", - "colab": {} + "id": "jQKnWrNtNsA8" }, "source": [ "# Grab all letters past the first letter all the way to the end of the string. This is a trivial example. \n", @@ -1190,9 +1090,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "otKc90t_NsBB", - "colab": {} + "id": "otKc90t_NsBB" }, "source": [ "# This does not change the original string in any way\n", @@ -1204,13 +1102,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "f9xrirSANsBD", + "outputId": "86717c0a-a18e-443f-9227-3f4aabd47cb4", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "86717c0a-a18e-443f-9227-3f4aabd47cb4" + } }, "source": [ "# Grab everything UP TO the 5th index\n", @@ -1238,7 +1135,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "5dp4GDO0NsBG" }, "source": [ @@ -1249,12 +1145,11 @@ "cell_type": "code", "metadata": { "id": "mfUzDlat-WqH", - "colab_type": "code", + "outputId": "81b3ecd9-d8b2-4295-8d76-bf74cb29bcb2", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "81b3ecd9-d8b2-4295-8d76-bf74cb29bcb2" + } }, "source": [ "# Grab everything from \"1\" to before \"o\"\n", @@ -1282,7 +1177,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "lksAiQL6NsBK" }, "source": [ @@ -1292,9 +1186,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "8TywqyZ-NsBL", - "colab": {} + "id": "8TywqyZ-NsBL" }, "source": [ "# Last letter (one index behind 0 so it loops back around)\n", @@ -1306,9 +1198,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "LTzPovveNsBO", - "colab": {} + "id": "LTzPovveNsBO" }, "source": [ "# Grab everything but the last letter\n", @@ -1320,7 +1210,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "XxBxY0SBNsBQ" }, "source": [ @@ -1330,9 +1219,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "D4GZPT3mNsBR", - "colab": {} + "id": "D4GZPT3mNsBR" }, "source": [ "# Grab everything, but go in step size of 1\n", @@ -1344,9 +1231,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "PjDfDe3gNsBU", - "colab": {} + "id": "PjDfDe3gNsBU" }, "source": [ "# Grab everything, but go in step size of 2\n", @@ -1358,9 +1243,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "5t-mgi-KNsBW", - "colab": {} + "id": "5t-mgi-KNsBW" }, "source": [ "# A handy way to reverse a string!\n", @@ -1372,7 +1255,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "jPCEC_LvfRZp" }, "source": [ @@ -1382,7 +1264,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "P1U1VtJENsBZ" }, "source": [ @@ -1393,18 +1274,17 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "xvPyEmYpNsBa", + "outputId": "9c133349-303b-4593-de9c-1b6dc11dd50f", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "9c133349-303b-4593-de9c-1b6dc11dd50f" + } }, "source": [ "mystring" ], - "execution_count": 4, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1426,19 +1306,18 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "NDk66bjZNsBc", + "outputId": "13f2c1c8-c6c1-43a3-a4fa-12e48d73bcb5", "colab": { "base_uri": "https://localhost:8080/", "height": 181 - }, - "outputId": "13f2c1c8-c6c1-43a3-a4fa-12e48d73bcb5" + } }, "source": [ "# Let's try to change the first letter\n", "mystring[0] = 'a'" ], - "execution_count": 5, + "execution_count": null, "outputs": [ { "output_type": "error", @@ -1456,7 +1335,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "p_Q9e1MoNsBf" }, "source": [ @@ -1468,9 +1346,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "MUaQkaxfNsBg", - "colab": {} + "id": "MUaQkaxfNsBg" }, "source": [ "mystring" @@ -1481,19 +1357,18 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "6MkkAvD9NsBk", + "outputId": "35d8bbdb-1d0d-4179-bd22-d1a1487c232c", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "35d8bbdb-1d0d-4179-bd22-d1a1487c232c" + } }, "source": [ "# Combine strings through concatenation\n", "mystring + \". It's me.\"" ], - "execution_count": 6, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1515,9 +1390,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "_BEU6-T0NsBn", - "colab": {} + "id": "_BEU6-T0NsBn" }, "source": [ "# We can reassign mystring to have a new value. \n", @@ -1529,9 +1402,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vdYO-sKKNsBq", - "colab": {} + "id": "vdYO-sKKNsBq" }, "source": [ "print(mystring)" @@ -1542,9 +1413,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "42B3Xw-KNsBt", - "colab": {} + "id": "42B3Xw-KNsBt" }, "source": [ "mystring" @@ -1555,7 +1424,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "n0u6E5p7NsBw" }, "source": [ @@ -1565,31 +1433,28 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "eFYcAGkWNsBw", - "colab": {} + "id": "eFYcAGkWNsBw" }, "source": [ "letter = 'a'" ], - "execution_count": 7, + "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "9W5K-pOqNsBy", + "outputId": "c43e5f57-5744-4d0f-e9aa-8f4abb63d21f", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "c43e5f57-5744-4d0f-e9aa-8f4abb63d21f" + } }, "source": [ "letter*20" ], - "execution_count": 8, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1611,7 +1476,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "m7KcM_wENsB1" }, "source": [ @@ -1629,18 +1493,17 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "NoO8TSuwNsB2", + "outputId": "7fb97c38-4956-4227-835e-510267a7044b", "colab": { "base_uri": "https://localhost:8080/", "height": 35 - }, - "outputId": "7fb97c38-4956-4227-835e-510267a7044b" + } }, "source": [ "mystring" ], - "execution_count": 9, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1662,9 +1525,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "7RyvdFNGNsB5", - "colab": {} + "id": "7RyvdFNGNsB5" }, "source": [ "# Make all letters in a string uppercase\n", @@ -1676,9 +1537,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "0sUWl6CANsB-", - "colab": {} + "id": "0sUWl6CANsB-" }, "source": [ "# Make all letters in a string lowercase\n", @@ -1690,9 +1549,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "z7tHM7qPNsCC", - "colab": {} + "id": "z7tHM7qPNsCC" }, "source": [ "# Split strings with a specified character as the separator. Spaces are the default.\n", @@ -1704,19 +1561,18 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "Rr-Qqn3tNsCH", + "outputId": "23962c42-9b51-4eba-8554-3819d9468493", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "23962c42-9b51-4eba-8554-3819d9468493" + } }, "source": [ "# Split by a specific character (doesn't include the character in the resulting string)\n", "mystring.split('W')" ], - "execution_count": 10, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1735,7 +1591,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "4o2jcAAhNsCL" }, "source": [ @@ -1745,7 +1600,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "IENyrelfNsCM" }, "source": [ @@ -1759,9 +1613,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "wxqKz5c8NsCM", - "colab": {} + "id": "wxqKz5c8NsCM" }, "source": [ "'The Eiffel Tower is in: {}'.format('Paris')" @@ -1772,9 +1624,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "ZtwDFyu7k0U6", - "colab": {} + "id": "ZtwDFyu7k0U6" }, "source": [ "# We can also use variables\n", @@ -1788,7 +1638,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "x90qHJh7DzpF" }, "source": [ @@ -1798,7 +1647,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "2jQg-dN0ZbY-" }, "source": [ @@ -1808,9 +1656,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "3G3a5dNZZbY_", - "colab": {} + "id": "3G3a5dNZZbY_" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", @@ -1828,7 +1674,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "ilw29z4OZbZE" }, "source": [ @@ -1838,9 +1683,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "BABsKQN4ZbZE", - "colab": {} + "id": "BABsKQN4ZbZE" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", @@ -1858,7 +1701,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "rgM2B4rmZbZI" }, "source": [ @@ -1868,9 +1710,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rZiItM7hZbZK", - "colab": {} + "id": "rZiItM7hZbZK" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it, this will save your code.\n", @@ -1889,7 +1729,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "hrXZof6r218Z" }, "source": [ @@ -1905,33 +1744,30 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "UGHMeXpD218a", - "colab": {} + "id": "UGHMeXpD218a" }, "source": [ "# Set object to be a boolean\n", "a = True" ], - "execution_count": 11, + "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "B7BmKhMA218d", + "outputId": "a1bb1525-e3c9-47e1-cb85-67c48b4b3861", "colab": { "base_uri": "https://localhost:8080/", "height": 34 - }, - "outputId": "a1bb1525-e3c9-47e1-cb85-67c48b4b3861" + } }, "source": [ "#Show\n", "a" ], - "execution_count": 12, + "execution_count": null, "outputs": [ { "output_type": "execute_result", @@ -1950,7 +1786,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "sdZjutML218i" }, "source": [ @@ -1960,9 +1795,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "CsA40nxa218j", - "colab": {} + "id": "CsA40nxa218j" }, "source": [ "# Output is boolean\n", @@ -1974,7 +1807,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Q0d2MOxp218p" }, "source": [ @@ -1984,9 +1816,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "-6L2eHxX218q", - "colab": {} + "id": "-6L2eHxX218q" }, "source": [ "# None placeholder\n", @@ -1998,9 +1828,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "5AkpZ6Gu218u", - "colab": {} + "id": "5AkpZ6Gu218u" }, "source": [ "# Show\n", @@ -2012,7 +1840,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "0VOMDbyu218x" }, "source": [ @@ -2022,7 +1849,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "06d6iMqfOk_Z" }, "source": [ @@ -2038,7 +1864,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UGViz_ZWjVTP" }, "source": [ @@ -2048,9 +1873,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "93uSScXTOk_a", - "colab": {} + "id": "93uSScXTOk_a" }, "source": [ "# Assign a list to a variable named my_list\n", @@ -2062,7 +1885,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "9ggyXUl8Ok_e" }, "source": [ @@ -2072,9 +1894,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "TPyS5RpIOk_g", - "colab": {} + "id": "TPyS5RpIOk_g" }, "source": [ "my_list = ['A string',23,100.232,'o']" @@ -2085,7 +1905,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "vRJ7rYkuOk_l" }, "source": [ @@ -2095,9 +1914,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "ukEGubDvOk_m", - "colab": {} + "id": "ukEGubDvOk_m" }, "source": [ "len(my_list)" @@ -2108,9 +1925,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "oWgtuVsmOk_q", - "colab": {} + "id": "oWgtuVsmOk_q" }, "source": [ "my_list = ['one','two','three',4,5]" @@ -2121,8 +1936,7 @@ { "cell_type": "markdown", "metadata": { - "id": "36AgITpA-UMi", - "colab_type": "text" + "id": "36AgITpA-UMi" }, "source": [ "Lists can be indexed the same way as strings. " @@ -2131,9 +1945,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "xDX7DN7uOk_t", - "colab": {} + "id": "xDX7DN7uOk_t" }, "source": [ "# Grab element at index 0\n", @@ -2145,9 +1957,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "4Z36l5JOOk_x", - "colab": {} + "id": "4Z36l5JOOk_x" }, "source": [ "# Grab index 1 and everything past it\n", @@ -2159,9 +1969,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "VjuHzfJvOk_1", - "colab": {} + "id": "VjuHzfJvOk_1" }, "source": [ "# Grab everything UP TO index 3\n", @@ -2173,7 +1981,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "a4zfPBV5Ok_4" }, "source": [ @@ -2183,9 +1990,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "34u_E9sVOk_5", - "colab": {} + "id": "34u_E9sVOk_5" }, "source": [ "my_list + ['new item']" @@ -2196,7 +2001,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "uWeYqzrdOk_8" }, "source": [ @@ -2206,9 +2010,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "iDezs3lnOk_8", - "colab": {} + "id": "iDezs3lnOk_8" }, "source": [ "my_list" @@ -2219,7 +2021,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "HpAWR1hJOlAA" }, "source": [ @@ -2229,9 +2030,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "eFNB5w3fOlAA", - "colab": {} + "id": "eFNB5w3fOlAA" }, "source": [ "# Reassign\n", @@ -2243,9 +2042,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "fm453awNOlAE", - "colab": {} + "id": "fm453awNOlAE" }, "source": [ "my_list" @@ -2256,7 +2053,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "R-yDV_PQOlAH" }, "source": [ @@ -2266,9 +2062,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "XNaw0iQKOlAI", - "colab": {} + "id": "XNaw0iQKOlAI" }, "source": [ "# Double the list\n", @@ -2280,9 +2074,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "RlKGPzVHOlAK", - "colab": {} + "id": "RlKGPzVHOlAK" }, "source": [ "# Again doubling is not permanent\n", @@ -2294,7 +2086,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "R9hddNpTtVc6" }, "source": [ @@ -2304,7 +2095,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "zjduIynaOlAP" }, "source": [ @@ -2316,9 +2106,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "A4xC0i8NOlAQ", - "colab": {} + "id": "A4xC0i8NOlAQ" }, "source": [ "# Create a new list\n", @@ -2330,7 +2118,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "qLfxNw4yOlAU" }, "source": [ @@ -2340,9 +2127,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "C-TiI_eUOlAV", - "colab": {} + "id": "C-TiI_eUOlAV" }, "source": [ "# Append\n", @@ -2354,9 +2139,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Jaj9-tzgOlAZ", - "colab": {} + "id": "Jaj9-tzgOlAZ" }, "source": [ "# Show\n", @@ -2368,7 +2151,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "7CIIhCgYOlAd" }, "source": [ @@ -2378,9 +2160,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "hnX-fPkBOlAe", - "colab": {} + "id": "hnX-fPkBOlAe" }, "source": [ "# Pop off the item with an index of 0\n", @@ -2392,9 +2172,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "JrMYJOQdOlAh", - "colab": {} + "id": "JrMYJOQdOlAh" }, "source": [ "# Show\n", @@ -2406,9 +2184,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "ttUAkqYWOlAl", - "colab": {} + "id": "ttUAkqYWOlAl" }, "source": [ "# Store the popped element in a variable. Remember, the default is to pop off the last element.\n", @@ -2420,9 +2196,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "XQhQbsqnOlAo", - "colab": {} + "id": "XQhQbsqnOlAo" }, "source": [ "popped_item" @@ -2433,9 +2207,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "avcnqEe0OlAq", - "colab": {} + "id": "avcnqEe0OlAq" }, "source": [ "# Show remaining list\n", @@ -2447,7 +2219,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "8Z-DqqQiOlAt" }, "source": [ @@ -2457,9 +2228,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "4W5S_ImiOlAu", - "colab": {} + "id": "4W5S_ImiOlAu" }, "source": [ "list1[100]" @@ -2470,7 +2239,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "YPVuQbfQOlAx" }, "source": [ @@ -2480,9 +2248,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "OhTzTsCqOlAy", - "colab": {} + "id": "OhTzTsCqOlAy" }, "source": [ "new_list = ['a','e','x','b','c']" @@ -2493,9 +2259,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "LXiwPqUCOlA4", - "colab": {} + "id": "LXiwPqUCOlA4" }, "source": [ "#Show\n", @@ -2507,8 +2271,7 @@ { "cell_type": "markdown", "metadata": { - "id": "nb_xdRuGBOdq", - "colab_type": "text" + "id": "nb_xdRuGBOdq" }, "source": [ "Use **sort** to organize the list. In this case, it will sort in alphabetical order, but if it was a list of numbers, it will sort from smallest to largest." @@ -2517,9 +2280,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "g3-2LXA8OlA_", - "colab": {} + "id": "g3-2LXA8OlA_" }, "source": [ "new_list.sort()" @@ -2530,9 +2291,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "xhx2Ct42OlA9", - "colab": {} + "id": "xhx2Ct42OlA9" }, "source": [ "new_list" @@ -2543,8 +2302,7 @@ { "cell_type": "markdown", "metadata": { - "id": "JHF-TOo5Bb9j", - "colab_type": "text" + "id": "JHF-TOo5Bb9j" }, "source": [ "Use **reverse** to reverse the order. Note that this is permanent! " @@ -2553,9 +2311,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "WskGGD9iOlA6", - "colab": {} + "id": "WskGGD9iOlA6" }, "source": [ "new_list.reverse()" @@ -2566,9 +2322,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "KVBuaoI0OlBD", - "colab": {} + "id": "KVBuaoI0OlBD" }, "source": [ "new_list" @@ -2579,7 +2333,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "ZMIKx3AjOlBH" }, "source": [ @@ -2592,9 +2345,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "-P9Wkw91OlBI", - "colab": {} + "id": "-P9Wkw91OlBI" }, "source": [ "# Let's make three lists\n", @@ -2611,9 +2362,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "eMKJk5cLOlBK", - "colab": {} + "id": "eMKJk5cLOlBK" }, "source": [ "# Show\n", @@ -2625,7 +2374,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "1CiTJaLFOlBN" }, "source": [ @@ -2635,9 +2383,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "fK_B1F2iOlBN", - "colab": {} + "id": "fK_B1F2iOlBN" }, "source": [ "# Grab first list (row) in the matrix object\n", @@ -2649,9 +2395,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "L2qEysM1OlBQ", - "colab": {} + "id": "L2qEysM1OlBQ" }, "source": [ "# Grab the first item of the first list in the matrix object\n", @@ -2663,7 +2407,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "z1QjkkW0pbVF" }, "source": [ @@ -2676,9 +2419,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "o7aDV8oipbVF", - "colab": {} + "id": "o7aDV8oipbVF" }, "source": [ "# Build a list comprehension by deconstructing a for loop within a []\n", @@ -2690,9 +2431,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vpLojxrypbVH", - "colab": {} + "id": "vpLojxrypbVH" }, "source": [ "first_col" @@ -2703,7 +2442,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "9G723yu0pbVK" }, "source": [ @@ -2713,7 +2451,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "jlS7xu6QFvqJ" }, "source": [ @@ -2723,7 +2460,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "IKYj6iiBZbZR" }, "source": [ @@ -2733,9 +2469,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "qvMc4qjWZbZY", - "colab": {} + "id": "qvMc4qjWZbZY" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", @@ -2752,7 +2486,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "TIvqQqsBZbZn" }, "source": [ @@ -2762,9 +2495,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "20643TYxZbZo", - "colab": {} + "id": "20643TYxZbZo" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", @@ -2781,7 +2512,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "v_zLIslPZbZw" }, "source": [ @@ -2791,9 +2521,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "IJZRvdN7ZbZx", - "colab": {} + "id": "IJZRvdN7ZbZx" }, "source": [ "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", @@ -2810,7 +2538,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "qDEeD8_NBbSc" }, "source": [ @@ -2824,7 +2551,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "WDYmdzPj935W" }, "source": [ @@ -2836,9 +2562,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "PI539KXHBbSe", - "colab": {} + "id": "PI539KXHBbSe" }, "source": [ "# Create a tuple\n", @@ -2850,9 +2574,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "dU_pWYhQBbSi", - "colab": {} + "id": "dU_pWYhQBbSi" }, "source": [ "# Check len just like a list\n", @@ -2864,9 +2586,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "QtnrN6_PBbSm", - "colab": {} + "id": "QtnrN6_PBbSm" }, "source": [ "# Can also mix object types\n", @@ -2881,9 +2601,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "xyu4CGwZBbSq", - "colab": {} + "id": "xyu4CGwZBbSq" }, "source": [ "# Use indexing just like we did in lists\n", @@ -2895,9 +2613,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "jVjWrQYUBbSt", - "colab": {} + "id": "jVjWrQYUBbSt" }, "source": [ "# Slicing just like a list\n", @@ -2909,7 +2625,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "DBLmUGHfBbSw" }, "source": [ @@ -2921,9 +2636,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "9iAxkxEfBbSx", - "colab": {} + "id": "9iAxkxEfBbSx" }, "source": [ "# Use .index to enter a value and return the index\n", @@ -2935,9 +2648,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "YxcUO8JhBbS2", - "colab": {} + "id": "YxcUO8JhBbS2" }, "source": [ "# Use .count to count the number of times a value appears\n", @@ -2949,7 +2660,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "gchvjroRBbS5" }, "source": [ @@ -2961,9 +2671,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "x5Omi4MfBbS6", - "colab": {} + "id": "x5Omi4MfBbS6" }, "source": [ "t[0]= 'change'" @@ -2974,7 +2682,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "DSTAAnzkBbS_" }, "source": [ @@ -2984,9 +2691,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "jNZlWZrzBbS_", - "colab": {} + "id": "jNZlWZrzBbS_" }, "source": [ "t.append('nope')" @@ -2997,7 +2702,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "rbJsQW4vBbTD" }, "source": [ @@ -3011,7 +2715,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "GavPLpw0GjP_" }, "source": [ @@ -3021,7 +2724,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "2XImAqwcZbaH" }, "source": [ @@ -3031,9 +2733,7 @@ { "cell_type": "code", "metadata": { - "id": "JNKxQlgfeIQx", - "colab_type": "code", - "colab": {} + "id": "JNKxQlgfeIQx" }, "source": [ "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", @@ -3050,23 +2750,23 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Gml2Q3rPOzP6" }, "source": [ "## Dictionaries\n", "\n", - "We've been learning about *sequences* in Python but now we're going to switch gears and learn about *mappings* in Python. If you're familiar with other languages you can think of dictionaries as hash tables. \n", + "We've been learning about *sequences* in Python but now we're going to switch gears and learn about *mappings*. \n", + "\n", + "Mapping is a one-to-one connection between a key and a value. Values are always data points that can be accessed through their respective key. This is called a key-value pairing. \n", "\n", - "So what are mappings? Mappings are a collection of objects that are stored by a *key*, unlike a sequence that stored objects by their relative position. This is an important distinction, since mappings won't retain order as is no *order* to keys..\n", + "A good example is an actual dictionary. The key is the word and the value is the definition of the word. To access the definition, you must find the key first. \n", "\n", - "A Python dictionary consists of a key and then an associated value. That value can be almost any Python object." + "A Python dictionary consists of a key and then an associated value. That value can be almost any Python object (string, integer, float, list, tuples, dictionary)." ] }, { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "j5v_alrd8KaO" }, "source": [ @@ -3077,9 +2777,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Ibt_zazrOzP7", - "colab": {} + "id": "Ibt_zazrOzP7" }, "source": [ "# Make a dictionary with {} and : to signify a key and a value\n", @@ -3091,9 +2789,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "UcpULUI4OzQC", - "colab": {} + "id": "UcpULUI4OzQC" }, "source": [ "# Call values by their key\n", @@ -3105,19 +2801,16 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "17-ijFwFOzQI" }, "source": [ - "Its important to note that dictionaries are very flexible in the data types they can hold. For example:" + "It's important to note that dictionaries are very flexible in the data types they can hold. For example:" ] }, { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "j7ZWMM7oOzQJ", - "colab": {} + "id": "j7ZWMM7oOzQJ" }, "source": [ "my_dict = {'key1':123,'key2':[12,23,33],'key3':['item0','item1','item2']}" @@ -3128,9 +2821,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "57kiUxF2OzQO", - "colab": {} + "id": "57kiUxF2OzQO" }, "source": [ "# Let's call items from the dictionary\n", @@ -3142,12 +2833,10 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "f0T3aDArOzQT", - "colab": {} + "id": "f0T3aDArOzQT" }, "source": [ - "# Can call an index on that value\n", + "# If the value is another data structure, you can even index it directly.\n", "my_dict['key3'][0]" ], "execution_count": null, @@ -3156,12 +2845,10 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "cB7xzb4FOzQY", - "colab": {} + "id": "cB7xzb4FOzQY" }, "source": [ - "# Can then even call methods on that value\n", + "# You can also call methods directly. \n", "my_dict['key3'][0].upper()" ], "execution_count": null, @@ -3170,19 +2857,16 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "VfbPr4MpOzQf" }, "source": [ - "We can affect the values of a key as well. For instance:" + "We can modify the values of a key as well. For instance:" ] }, { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "5P_IW7-wOzQh", - "colab": {} + "id": "5P_IW7-wOzQh" }, "source": [ "my_dict['key1']" @@ -3193,9 +2877,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "_JE2n8BLOzQn", - "colab": {} + "id": "_JE2n8BLOzQn" }, "source": [ "# Subtract 123 from the value\n", @@ -3207,9 +2889,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "UZQnyDq3OzQq", - "colab": {} + "id": "UZQnyDq3OzQq" }, "source": [ "#Check\n", @@ -3221,32 +2901,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", - "id": "Ba8UE39VOzQv" - }, - "source": [ - "A quick note, Python has a built-in method of doing a self subtraction or addition (or multiplication or division). We could have also used += or -= for the above statement. For example:" - ] - }, - { - "cell_type": "code", - "metadata": { - "colab_type": "code", - "id": "enQczBulOzQw", - "colab": {} - }, - "source": [ - "# Set the object equal to itself minus 123 \n", - "my_dict['key1'] -= 123\n", - "my_dict['key1']" - ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", "id": "Ym1tQXryOzQ0" }, "source": [ @@ -3256,9 +2910,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "XYTOL_t6OzQ0", - "colab": {} + "id": "XYTOL_t6OzQ0" }, "source": [ "# Create a new dictionary\n", @@ -3270,9 +2922,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "6cxK3dXhOzQ4", - "colab": {} + "id": "6cxK3dXhOzQ4" }, "source": [ "# Create a new key through assignment\n", @@ -3284,12 +2934,10 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "2udYamqwOzQ7", - "colab": {} + "id": "2udYamqwOzQ7" }, "source": [ - "# Can do this with any object\n", + "# You can do this with any object\n", "d['answer'] = 42" ], "execution_count": null, @@ -3298,9 +2946,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "LIICwuVGOzQ_", - "colab": {} + "id": "LIICwuVGOzQ_" }, "source": [ "#Show\n", @@ -3312,7 +2958,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "lQjKGTqyOzRD" }, "source": [ @@ -3324,9 +2969,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "SqlnsrceOzRD", - "colab": {} + "id": "SqlnsrceOzRD" }, "source": [ "# Dictionary nested inside a dictionary nested inside a dictionary\n", @@ -3338,7 +2981,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "S9j8ZHcvOzRG" }, "source": [ @@ -3348,12 +2990,34 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vbNLXS9COzRH", - "colab": {} + "id": "uLL6nw4XxIwG" + }, + "source": [ + "# Access the first value\n", + "d['key1']" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "9KgKFDcDxFdl" }, "source": [ - "# Keep calling the keys\n", + "# Access the second value\n", + "d['key1']['nestkey']" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "vbNLXS9COzRH" + }, + "source": [ + "# Finally, access the target value\n", "d['key1']['nestkey']['subnestkey']" ], "execution_count": null, @@ -3362,7 +3026,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "aToEjqLPOzRK" }, "source": [ @@ -3374,23 +3037,19 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "NizEqIn3OzRK", - "colab": {} + "id": "NizEqIn3OzRK" }, "source": [ "# Create a typical dictionary\n", "d = {'key1':1,'key2':2,'key3':3}" ], - "execution_count": null, + "execution_count": 1, "outputs": [] }, { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "F_d4EiF0OzRN", - "colab": {} + "id": "F_d4EiF0OzRN" }, "source": [ "# Method to return a list of all keys \n", @@ -3402,9 +3061,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vXhVyVd3OzRP", - "colab": {} + "id": "vXhVyVd3OzRP" }, "source": [ "# Method to grab all values\n", @@ -3416,21 +3073,36 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", "id": "JPkBFpoGOzRR", - "colab": {} + "outputId": "2bd7d1f4-6305-4090-a20f-1911cc44df98", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } }, "source": [ - "# Method to return tuples of all items (we'll learn about tuples soon)\n", + "# Method to return list of all key-value pairings as tuples\n", "d.items()" ], - "execution_count": null, - "outputs": [] + "execution_count": 2, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "dict_items([('key1', 1), ('key2', 2), ('key3', 3)])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 2 + } + ] }, { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "jljY3mE2G-oX" }, "source": [ @@ -3440,7 +3112,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "MAp2fG9nZbZ6" }, "source": [ @@ -3450,14 +3121,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "5nfaiz0yZbZ6", - "colab": {} + "id": "5nfaiz0yZbZ6" }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/4.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and press the play button multiple times, the program will keep appending to the file.\n", "# So only uncomment it when you want to save your answer.\n", "\n", "d = {'simple_key':'hello'}\n", @@ -3472,14 +3141,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "2ddxOLcqZbZ9", - "colab": {} + "id": "2ddxOLcqZbZ9" }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/4.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and press the play button multiple times, the program will keep appending to the file.\n", "# So only uncomment it when you want to save your answer.\n", "\n", "d = {'k1':{'k2':'hello'}}\n", @@ -3494,14 +3161,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rJlGHUFTZbaA", - "colab": {} + "id": "rJlGHUFTZbaA" }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/4.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and press the play button multiple times, the program will keep appending to the file.\n", "# So only uncomment it when you want to save your answer.\n", "\n", "# Getting a little tricker\n", @@ -3517,14 +3182,12 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "vjadbMt3ZbaE", - "colab": {} + "id": "vjadbMt3ZbaE" }, "source": [ - "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", + "# Once your have verified your answer, please uncomment the line below and run it. This will save your code. \n", "#%%writefile -a {folder_location}/4.py\n", - "# Please note that if you uncomment and press multiple times, the program will keep appending to the file.\n", + "# Please note that if you uncomment and press the play button multiple times, the program will keep appending to the file.\n", "# So only uncomment it when you want to save your answer.\n", "\n", "# This will be hard and annoying!\n", @@ -3540,7 +3203,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "_d9-nOtO28os" }, "source": [ @@ -3550,7 +3212,7 @@ "\n", "These operators are the exact same as what you've seen in Math, so there's nothing new here.\n", "\n", - "First we'll present a table of the comparison operators and then work through some examples:\n", + "First, we'll present a table of the comparison operators and then work through some examples:\n", "\n", "

Table of Comparison Operators

In the table below, a=9 and b=11.

\n", "\n", @@ -3594,7 +3256,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Oxyatrdj28ow" }, "source": [ @@ -3606,9 +3267,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rPThJGsl28ox", - "colab": {} + "id": "rPThJGsl28ox" }, "source": [ "4 == 4" @@ -3619,9 +3278,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "W2W27aBp28o1", - "colab": {} + "id": "W2W27aBp28o1" }, "source": [ "1 == 0" @@ -3632,7 +3289,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "gtzQpCPO28o5" }, "source": [ @@ -3642,7 +3298,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "4FSgFc8y28o5" }, "source": [ @@ -3652,9 +3307,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "BNQaWArv28o6", - "colab": {} + "id": "BNQaWArv28o6" }, "source": [ "4 != 5" @@ -3665,9 +3318,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "D9hVgJsD28o9", - "colab": {} + "id": "D9hVgJsD28o9" }, "source": [ "1 != 1" @@ -3678,7 +3329,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "iVvotha-28pD" }, "source": [ @@ -3688,9 +3338,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "qA1VVR7128pI", - "colab": {} + "id": "qA1VVR7128pI" }, "source": [ "8 > 3" @@ -3701,9 +3349,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "PrZb9Zy_28pN", - "colab": {} + "id": "PrZb9Zy_28pN" }, "source": [ "1 > 9" @@ -3714,7 +3360,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "PYK9vEa-28pT" }, "source": [ @@ -3724,9 +3369,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "f5x67fWk28pU", - "colab": {} + "id": "f5x67fWk28pU" }, "source": [ "3 < 8" @@ -3737,9 +3380,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "1eB15ns928pX", - "colab": {} + "id": "1eB15ns928pX" }, "source": [ "7 < 0" @@ -3750,7 +3391,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "wDXSDbik28pa" }, "source": [ @@ -3760,9 +3400,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "k4BQs2oB28pb", - "colab": {} + "id": "k4BQs2oB28pb" }, "source": [ "7 >= 7" @@ -3773,9 +3411,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "BPBKLDtb28pd", - "colab": {} + "id": "BPBKLDtb28pd" }, "source": [ "9 >= 4" @@ -3786,7 +3422,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "ai1kLMhy28pi" }, "source": [ @@ -3796,9 +3431,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "5KuB4wd028pi", - "colab": {} + "id": "5KuB4wd028pi" }, "source": [ "4 <= 4" @@ -3809,9 +3442,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "YFbO6yih28pl", - "colab": {} + "id": "YFbO6yih28pl" }, "source": [ "1 <= 3" @@ -3822,17 +3453,15 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "eIDePOLk28po" }, "source": [ - "Hopefully this was more of a review than anything new! Next, we move on to one of the most important aspects of building programs: functions and how to use them." + "Hopefully this was more of a review than anything new! Next, we move on to one of the most important aspects of building programs: functions." ] }, { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "JWmMpmPaNWcX" }, "source": [ @@ -3840,13 +3469,13 @@ "\n", "### Introduction to Functions\n", "\n", - "Here, we will explain what a function is in Python and how to create one. Functions will be one of our main building blocks when we construct larger and larger amounts of code to solve problems.\n", + "In data science, you will come across issue where you would have to run a piece of code again and again inputting a different variable for every one run. This can get exhaustaing and is also very inefficient. Luckily, programming tools have something known as functions. \n", "\n", "**So what is a function?**\n", "\n", - "Formally, a function is a useful device that groups together a set of statements so they can be run more than once. They can also let us specify parameters that can serve as inputs to the functions.\n", + "A function allows you to re run the same piece of code multiple times without manually having to change every line. \n", "\n", - "On a more fundamental level, functions allow us to not have to repeatedly write the same code again and again. If you remember back to the lessons on strings and lists, remember that we used a function len() to get the length of a string. Since checking the length of a sequence is a common task you would want to write a function that can do this repeatedly at command.\n", + "On a more fundamental level, functions allow us to not have to repeatedly write the same code again and again. If you remember back to the lessons on strings and lists, remember that we used a function len() to get the length of a string. Since checking the length of a sequence is a common task, you would want to write a function that can do this repeatedly at command.\n", "\n", "Functions will be one of most basic levels of reusing code in Python, and it will also allow us to start thinking of program design." ] @@ -3854,7 +3483,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "-ghJ1ZQJNWcZ" }, "source": [ @@ -3866,9 +3494,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "b6z3S5eaNWca", - "colab": {} + "id": "b6z3S5eaNWca" }, "source": [ "def name_of_function(arg1,arg2):\n", @@ -3884,7 +3510,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "fUoJtJgHNWcf" }, "source": [ @@ -3904,7 +3529,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "bybS0BdINWcf" }, "source": [ @@ -3914,9 +3538,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "QXDcJHwcNWcg", - "colab": {} + "id": "QXDcJHwcNWcg" }, "source": [ "def say_hello():\n", @@ -3928,7 +3550,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "CfOFuqNENWcj" }, "source": [ @@ -3938,9 +3559,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "yP0KFROlNWck", - "colab": {} + "id": "yP0KFROlNWck" }, "source": [ "say_hello()" @@ -3951,7 +3570,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "HK25wgkKNWcn" }, "source": [ @@ -3962,9 +3580,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "THien-GyNWcp", - "colab": {} + "id": "THien-GyNWcp" }, "source": [ "def greeting(name):\n", @@ -3976,9 +3592,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "-P1sYGzENWcu", - "colab": {} + "id": "-P1sYGzENWcu" }, "source": [ "greeting('Bob')" @@ -3989,7 +3603,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "6im_y8_9NWcx" }, "source": [ @@ -4002,9 +3615,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "o3Lmm8SgNWcy", - "colab": {} + "id": "o3Lmm8SgNWcy" }, "source": [ "def add_num(num1,num2):\n", @@ -4016,9 +3627,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rl_WvYjkNWc1", - "colab": {} + "id": "rl_WvYjkNWc1" }, "source": [ "add_num(4,5)" @@ -4029,9 +3638,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "VuEvJPq1NWc5", - "colab": {} + "id": "VuEvJPq1NWc5" }, "source": [ "# Can also save as variable due to return\n", @@ -4043,9 +3650,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "f0ad5-kaNWc8", - "colab": {} + "id": "f0ad5-kaNWc8" }, "source": [ "print(result)" @@ -4056,7 +3661,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "15lkNnVPNWc_" }, "source": [ @@ -4066,9 +3670,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "1hlftLo7NWc_", - "colab": {} + "id": "1hlftLo7NWc_" }, "source": [ "add_num('one','two')" @@ -4079,7 +3681,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "eBJTPKYjNWdD" }, "source": [ @@ -4091,7 +3692,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "FQQ7-olXNWdD" }, "source": [ @@ -4103,9 +3703,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "o82eSDSaNWdE", - "colab": {} + "id": "o82eSDSaNWdE" }, "source": [ "def is_prime(num):\n", @@ -4125,9 +3723,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "68obU1f7NWdH", - "colab": {} + "id": "68obU1f7NWdH" }, "source": [ "is_prime(16)" @@ -4138,9 +3734,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "uqlUE7j2NWdK", - "colab": {} + "id": "uqlUE7j2NWdK" }, "source": [ "is_prime(17)" @@ -4151,7 +3745,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "rPO1ypnINWdN" }, "source": [ @@ -4165,9 +3758,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "1sMwpbK0NWdO", - "colab": {} + "id": "1sMwpbK0NWdO" }, "source": [ "import math\n", @@ -4189,9 +3780,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "4vVcaf4nNWdR", - "colab": {} + "id": "4vVcaf4nNWdR" }, "source": [ "is_prime2(27)" @@ -4202,7 +3791,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "OpfJdTpDNWdV" }, "source": [ @@ -4212,7 +3800,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "K5hLnLVZJXXv" }, "source": [ @@ -4222,7 +3809,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UxCgXtLgIEEf" }, "source": [ @@ -4236,9 +3822,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "3KDqoGkGIEEf", - "colab": {} + "id": "3KDqoGkGIEEf" }, "source": [ "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", @@ -4260,7 +3844,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "LHJ8OPspOM6v" }, "source": [ @@ -4272,9 +3855,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "2_p-4eSUOM6w", - "colab": {} + "id": "2_p-4eSUOM6w" }, "source": [ "print('Hello)" @@ -4285,7 +3866,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "YAw5d8J3OM61" }, "source": [ @@ -4299,7 +3879,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "BH3W9o4jOM62" }, "source": [ @@ -4324,9 +3903,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "d16XniIaOM64", - "colab": {} + "id": "d16XniIaOM64" }, "source": [ "try:\n", @@ -4345,7 +3922,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "veniFyBbOM69" }, "source": [ @@ -4355,9 +3931,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "DUUZn6mHOM69", - "colab": {} + "id": "DUUZn6mHOM69" }, "source": [ "try:\n", @@ -4376,7 +3950,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "Hk_N9KNzOM7D" }, "source": [ @@ -4388,9 +3961,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "86ypth81OM7E", - "colab": {} + "id": "86ypth81OM7E" }, "source": [ "try:\n", @@ -4409,7 +3980,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "lCAcBb9IOM7M" }, "source": [ @@ -4430,9 +4000,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "11uq4IIYOM7O", - "colab": {} + "id": "11uq4IIYOM7O" }, "source": [ "try:\n", @@ -4448,7 +4016,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "xWSjapK7OM7Y" }, "source": [ @@ -4458,9 +4025,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "eRyp48dYOM7a", - "colab": {} + "id": "eRyp48dYOM7a" }, "source": [ "def askint():\n", @@ -4479,9 +4044,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "oOpUzWc6OM7k", - "colab": {} + "id": "oOpUzWc6OM7k" }, "source": [ "askint()" @@ -4492,9 +4055,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "DRdDnSXMOM7z", - "colab": {} + "id": "DRdDnSXMOM7z" }, "source": [ "askint()" @@ -4505,7 +4066,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "U7NSCfOoOM76" }, "source": [ @@ -4515,9 +4075,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "a9A4mdRYOM78", - "colab": {} + "id": "a9A4mdRYOM78" }, "source": [ "def askint():\n", @@ -4536,9 +4094,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "dgyMsjl2OM8D", - "colab": {} + "id": "dgyMsjl2OM8D" }, "source": [ "askint()" @@ -4549,7 +4105,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "KC6gX2SMOM8H" }, "source": [ @@ -4559,9 +4114,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "r7jC8D4GOM8I", - "colab": {} + "id": "r7jC8D4GOM8I" }, "source": [ "def askint():\n", @@ -4584,9 +4137,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "xc6saFw4OM8N", - "colab": {} + "id": "xc6saFw4OM8N" }, "source": [ "askint()" @@ -4597,7 +4148,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "tqlEV-zQOM8R" }, "source": [ @@ -4609,9 +4159,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "K4g8YusIOM8S", - "colab": {} + "id": "K4g8YusIOM8S" }, "source": [ "def askint():\n", @@ -4634,9 +4182,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "E11t6GKuOM8W", - "colab": {} + "id": "E11t6GKuOM8W" }, "source": [ "askint()" @@ -4647,7 +4193,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "vaBOcf3wKmnq" }, "source": [ @@ -4657,7 +4202,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "R03RpvhvKbJC" }, "source": [ @@ -4667,9 +4211,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "zysaDxeoKbJC", - "colab": {} + "id": "zysaDxeoKbJC" }, "source": [ "# Once your have verified your answer please uncomment the line below and run it, this will save your code \n", @@ -4690,7 +4232,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "IUBg9zS8GT96" }, "source": [ @@ -4700,7 +4241,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "EZGgT39kGT-Y" }, "source": [ @@ -4718,9 +4258,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "pINzCtawGT-Z", - "colab": {} + "id": "pINzCtawGT-Z" }, "source": [ "# import the library\n", @@ -4732,9 +4270,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "wOBwO2RiGT-c", - "colab": {} + "id": "wOBwO2RiGT-c" }, "source": [ "# use it (ceiling rounding)\n", @@ -4746,7 +4282,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "B__qpOe-GT-o" }, "source": [ @@ -4757,7 +4292,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UynSepC2cLfX" }, "source": [ @@ -4767,9 +4301,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "j_Y4057OGT98", - "colab": {} + "id": "j_Y4057OGT98" }, "source": [ "%%writefile myfile.py\n", @@ -4783,7 +4315,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "aoUBNiqiGT-C" }, "source": [ @@ -4798,9 +4329,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "dSv_ahmsGT-C", - "colab": {} + "id": "dSv_ahmsGT-C" }, "source": [ "%%writefile myfile2.py\n", @@ -4814,7 +4343,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "jZQOviqScRNu" }, "source": [ @@ -4829,7 +4357,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "hfnOwvD1GT-G" }, "source": [ @@ -4841,9 +4368,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "sVx44Sb9GT-G", - "colab": {} + "id": "sVx44Sb9GT-G" }, "source": [ "! python myfile2.py" @@ -4854,7 +4379,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "VRgQSGckGT-J" }, "source": [ @@ -4864,9 +4388,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "x4dy5kZeGT-K", - "colab": {} + "id": "x4dy5kZeGT-K" }, "source": [ "import myfile\n", @@ -4878,7 +4400,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "anK1GyS5GT-N" }, "source": [ @@ -4888,7 +4409,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "UxlbVOqlGT-O" }, "source": [ @@ -4899,9 +4419,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "1x1oE-KtGT-P", - "colab": {} + "id": "1x1oE-KtGT-P" }, "source": [ "%%writefile myfile3.py\n", @@ -4916,7 +4434,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "F5HEmqPKGT-S" }, "source": [ @@ -4927,9 +4444,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "fyJeVNs8GT-U", - "colab": {} + "id": "fyJeVNs8GT-U" }, "source": [ "! python myfile3.py 21" @@ -4940,7 +4455,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "WaU1qym5GT-Y" }, "source": [ @@ -4950,7 +4464,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "KWdrfQP2GT-g" }, "source": [ @@ -4963,9 +4476,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "Frdlk-C3GT-g", - "colab": {} + "id": "Frdlk-C3GT-g" }, "source": [ "print(dir(math))" @@ -4976,7 +4487,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "kV9kfcvBGT-j" }, "source": [ @@ -4987,9 +4497,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "nQfohp4BGT-l", - "colab": {} + "id": "nQfohp4BGT-l" }, "source": [ "help(math.ceil)" @@ -5000,7 +4508,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "YFiS7660_YlX" }, "source": [ @@ -5017,9 +4524,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "rZyb1oyrGT-o", - "colab": {} + "id": "rZyb1oyrGT-o" }, "source": [ "# Just an example, this won't work\n", @@ -5031,9 +4536,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "nAblu0pxGT-r", - "colab": {} + "id": "nAblu0pxGT-r" }, "source": [ "# OR could do it this way\n", @@ -5045,7 +4548,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "_b2Kn1ytGT-w" }, "source": [ @@ -5057,9 +4559,7 @@ { "cell_type": "code", "metadata": { - "colab_type": "code", - "id": "d0NNLlkQGT-w", - "colab": {} + "id": "d0NNLlkQGT-w" }, "source": [ "__init__.py:\n", @@ -5072,7 +4572,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "cJiazN8PJ6Wz" }, "source": [ @@ -5084,7 +4583,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "kkhCZ9fNLxRt" }, "source": [ @@ -5094,7 +4592,6 @@ { "cell_type": "markdown", "metadata": { - "colab_type": "text", "id": "zc_kzXmgMTge" }, "source": [ @@ -5106,8 +4603,7 @@ { "cell_type": "markdown", "metadata": { - "id": "FqS9ZqyneIS_", - "colab_type": "text" + "id": "FqS9ZqyneIS_" }, "source": [ "## Submission\n", @@ -5117,9 +4613,7 @@ { "cell_type": "code", "metadata": { - "id": "lQLSe4cteIS_", - "colab_type": "code", - "colab": {} + "id": "lQLSe4cteIS_" }, "source": [ "from google.colab import files\n",