\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",