From 503638bf86403d823018f24fc28d02400a441479 Mon Sep 17 00:00:00 2001 From: Jessime Date: Thu, 6 Jun 2019 22:51:06 -0700 Subject: [PATCH 1/2] Reviewed lesson 1 Made a few small changes to the boolean and comparisons sections. --- Lesson_1.ipynb | 1401 +++++++++++++++++++++++++++--------------------- 1 file changed, 797 insertions(+), 604 deletions(-) diff --git a/Lesson_1.ipynb b/Lesson_1.ipynb index 546ffb5..a2370f2 100644 --- a/Lesson_1.ipynb +++ b/Lesson_1.ipynb @@ -1,617 +1,810 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Lesson 1.ipynb", - "version": "0.3.2", - "provenance": [], - "collapsed_sections": [], - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "view-in-github" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "JA9KlIebOBa3" + }, + "source": [ + "## Lesson 1 - Set up and the basics\n", + "\n", + "Learning objective: Students will be comfortable doing basic commands in Jupyter notebooks. \n", + "\n", + "**Specific coding skills:**\n", + "\n", + "\n", + "* basic math operators (+, -, *, /)\n", + "* assignment operator (=)\n", + "* basic functions (len(), type())\n", + "* common data classes (integer, float, string, boolean)\n", + "* comparison operators (>, <, ==, >=, <=) \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ohVu10_HF8WU" + }, + "source": [ + "### Introduction to jupyter\n", + "\n", + "\"The Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects. A notebook integrates code and its output into a single document that combines visualizations, narrative text, mathematical equations, and other rich media. The intuitive workflow promotes iterative and rapid development, making notebooks an increasingly popular choice at the heart of contemporary data science, analysis, and increasingly science at large. \" - [dataquest](https://www.dataquest.io/blog/jupyter-notebook-tutorial/)\n", + "\n", + "All of our lessons will be presented in jupyter notebooks. You can follow along in a partially filled out jupyter notebook and fill in lessons as you go. Let's get started! \n", + "\n", + "Each cell can include text (like this one) or code. To run the python code in a cell, you just hit shift + enter. Try it with the code below.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "cz-05_Z5N-Ko" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World!\n" + ] } + ], + "source": [ + "print(\"Hello World!\")" + ] }, - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "JA9KlIebOBa3", - "colab_type": "text" - }, - "source": [ - "## Lesson 1 - Set up and the basics\n", - "\n", - "Learning objective: Students will be comfortable doing basic commands in Jupyter notebooks. \n", - "\n", - "**Specific coding skills:**\n", - "\n", - "\n", - "* basic math operators (+, -, *, /)\n", - "* assignment operator (=)\n", - "* basic functions (len(), type())\n", - "* common data classes (integer, float, string, boolean)\n", - "* comparison operators (>, <, ==, >=, <=) \n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ohVu10_HF8WU", - "colab_type": "text" - }, - "source": [ - "### Introduction to jupyter\n", - "\n", - "\"The Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects. A notebook integrates code and its output into a single document that combines visualizations, narrative text, mathematical equations, and other rich media. The intuitive workflow promotes iterative and rapid development, making notebooks an increasingly popular choice at the heart of contemporary data science, analysis, and increasingly science at large. \" - [dataquest](https://www.dataquest.io/blog/jupyter-notebook-tutorial/)\n", - "\n", - "All of our lessons will be presented in jupyter notebooks. You can follow along in a partially filled out jupyter notebook and fill in lessons as you go. Let's get started! \n", - "\n", - "Each cell can include text (like this one) or code. To run the python code in a cell, you just hit shift + enter. Try it with the code below.\n" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "cz-05_Z5N-Ko", - "colab_type": "code", - "colab": {} - }, - "source": [ - "print(\"Hello World!\")" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "RLq-CchwAGvP", - "colab_type": "text" - }, - "source": [ - "### Basic math operators\n", - "Python can do math for you, which is convenient. To get used to doing writing and running code in jupyter, we're going to do some basic math. Let's calculate the following expressions:\n", - "\n", - "$$ 2 + 3 $$" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "W2okep-wAeLi", - "colab_type": "code", - "colab": {} - }, - "source": [ - "2+3" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "qgxIbZKpAo6v", - "colab_type": "text" - }, - "source": [ - "$$ \\frac{6}{2} * 20 +100 $$" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "CutTFG-vAx4O", - "colab_type": "code", - "colab": {} - }, - "source": [ - "6/2*20+100" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "jRoD3bj5A8Um", - "colab_type": "text" - }, - "source": [ - "$$ 2^{24} $$" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "6UBGcCmtA30K", - "colab_type": "code", - "colab": {} - }, - "source": [ - "2^(24)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "aMHMguWaBQXF", - "colab_type": "text" - }, - "source": [ - "Did you get the answer you expected for the last problem? If you used a `^` for the exponent you got the answer 26, which definitely isn't right. It is important to check the answers you get from code to make sure they seem reasonable. If they don't seem right, there is probably a bug in your code. \n", - "\n", - "In python you have to use `**` for exponents. The `^` operator is used for bit-wise XOR in python (and many other programming languages), which we will not discuss in this class. Try again using this `**` operator!" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "2hgyLorIBE-u", - "colab_type": "code", - "colab": {} - }, - "source": [ - "2**24" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "TMTq6N5YCJIw", - "colab_type": "text" - }, - "source": [ - "That's better! Make sure you use `**` any time you need to use exponents." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "w0JespP9CxHF", - "colab_type": "text" - }, - "source": [ - "### The assignment operator\n", - "\n", - "It is convenient to have python store and remember variables so you can use them later. You can do this with the assignment operator (`=`). Let's assign a few variables." - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "dULAPQ9FCHJs", - "colab_type": "code", - "colab": {} - }, - "source": [ - "x = 1\n", - "y = 2\n", - "z = 3\n", - "print(x, y, z)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "653q09cPDx6n", - "colab_type": "text" - }, - "source": [ - "Here you can see that we assigned the values 1, 2, and 3 to the variables `x`, `y`, and `z` respectively. We then printed x, y, and z to see what the values were. Try assigning variables yourself. Assign 2, 4, and 8 to `a`, `b`, and `c` respectively. " - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "QXwu1qgWDwPW", - "colab_type": "code", - "colab": {} - }, - "source": [ - "a = 2\n", - "b = 4\n", - "c = 8" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4lrj8FS3EhvC", - "colab_type": "text" - }, - "source": [ - "Notice that if you don't include a `print()` statement, running the cell doesn't return anything. That's okay though; the variables are still assigned (unless you got an error). \n", - "\n", - "Now we can easily call our variables and do basic operations with them. Calculate the following:\n", - "$$ x + b $$\n", - "$$ z * c $$\n", - "$$ \\left(\\frac{b}{y}\\right) ^ z $$" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "lYA3JMNVEfzp", - "colab_type": "code", - "colab": {} - }, - "source": [ - "x+b\n", - "z*c\n", - "(b/y)**z" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "TyEB5EgBFnJ-", - "colab_type": "text" - }, - "source": [ - "Notice that only the last solution is returned. If you want all of the solutions to be returned, include print statements." - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "QnTGUc1NFkaK", - "colab_type": "code", - "colab": {} - }, - "source": [ - "print(x+b)\n", - "print(z*c)\n", - "print((b/y)**z)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "2Mg9-mAEKPBO", - "colab_type": "text" - }, - "source": [ - "### Data types\n", - "In this class we will be focusing on four main data types\n", - "* string\n", - "* integer\n", - "* float\n", - "* boolean" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "V0zIo5U5MaY7", - "colab_type": "text" - }, - "source": [ - "#### Strings\n", - "Strings are essentially text. We used a string in our very first cell when we ran `print(\"Hello World!\")`. `\"Hello World!\"` is a string. You can assign strings to variables and call them, just like we did with numbers in the previous section. Here is an example:" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "dT2a94G9KPk8", - "colab_type": "code", - "colab": {} - }, - "source": [ - "str1 = 'GCGCTCAAT'\n", - "str2 = 'TACTAGGCA'\n", - "str3 = 'AATCGCTAG'\n", - "print(str1, str2, str3)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "y4btRsSXNWzb", - "colab_type": "text" - }, - "source": [ - "#### Integers\n", - "Integers are positive or negative whole numbers with no decimals. We have already used a few in this lesson like our variables `a`, `b`, `c`, `x`, `y`, and `z`." - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "Sd2NQktfN-Pa", - "colab_type": "code", - "colab": {} - }, - "source": [ - "print(a, b, c, x, y, z)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "7l9OhHeCOKwj", - "colab_type": "text" - }, - "source": [ - "#### Floats\n", - "Floats, short for floating point real values, are positive or negative numbers with decimals. You saw some when we did division. Like integers, floats can also be assigned to variables and used to do arithmetic. " - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "OT1bdd10Owb1", - "colab_type": "code", - "colab": {} - }, - "source": [ - "f1 = 4.2\n", - "f2 = 3.0\n", - "f3 = -2.1\n", - "print(f1, f2, f3, f1+f3)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "bOSayuNbQT5j", - "colab_type": "text" - }, - "source": [ - "#### Booleans\n", - "Booleans are either `True` or `False`. They are often used for comparisons (for example, `1>2` would result in `False`). You can assign Booleans to variables. Additionally, `True` behaves like `1` and `False` behaves like `0` in arithmetic operations. " + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "RLq-CchwAGvP" + }, + "source": [ + "### Basic math operators\n", + "Python can do math for you, which is convenient. To get used to doing writing and running code in jupyter, we're going to do some basic math. Let's calculate the following expressions:\n", + "\n", + "$$ 2 + 3 $$" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "W2okep-wAeLi" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "5" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "YT0PNRinRRmY", - "colab_type": "code", - "colab": {} - }, - "source": [ - "T = True\n", - "F = False\n", - "print(2*T)\n", - "print(2*F)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "L42-ZXlERhZ7", - "colab_type": "text" - }, - "source": [ - "### Comparison operators\n", - "Comparison operators (>, <, ==, >=, <=) work like you would expect them to and give a result in the form of a boolean. Let's try a few comparisons (remember to use print statements to see all of the results).\n", - "$$ 2>1 $$\n", - "$$ 4<=2 $$\n", - "$$ 5==5 $$\n", - "$$ 6>=6$$\n", - "$$ 7<3 $$" + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2+3" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "qgxIbZKpAo6v" + }, + "source": [ + "$$ \\frac{6}{2} * 20 +100 $$" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "CutTFG-vAx4O" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "160.0" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "52io3zdvSWcr", - "colab_type": "code", - "colab": {} - }, - "source": [ - "print(2 > 1.5)\n", - "print(4 <= 2)\n", - "print(5 == 5.0)\n", - "print(6 >= 6)\n", - "print(7.4 < 3)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "gnIb349tSmep", - "colab_type": "text" - }, - "source": [ - "Python will coerce integers to floats (for example change `2` to `2.0`) in order to compare the different data types. " + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "6/2*20+100" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "jRoD3bj5A8Um" + }, + "source": [ + "$$ 2^{24} $$" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "6UBGcCmtA30K" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "26" ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "QGa5ZQSVGEPB", - "colab_type": "text" - }, - "source": [ - "### Basic functions\n", - "\n", - "We've already started using one basic function, `print()`. You may have already figured out what it does, but it prints the information inside the parenthese to the cell output. Since you have already had some practice with that. Let's explore some other basic functions. \n", - "\n", - "The function `type()` returns the data type of the argument you pass it. See the example below:" + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2^(24)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "aMHMguWaBQXF" + }, + "source": [ + "Did you get the answer you expected for the last problem? If you used a `^` for the exponent you got the answer 26, which definitely isn't right. It is important to check the answers you get from code to make sure they seem reasonable. If they don't seem right, there is probably a bug in your code. \n", + "\n", + "In python you have to use `**` for exponents. The `^` operator is used for bit-wise XOR in python (and many other programming languages), which we will not discuss in this class. Try again using this `**` operator!" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "2hgyLorIBE-u" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "16777216" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "_o7xVv_kFzle", - "colab_type": "code", - "colab": {} - }, - "source": [ - "type(2.1)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "HtkhsWOdWzie", - "colab_type": "text" - }, - "source": [ - "Now use `type()` to find the data type of the following objects: `1`, `True`, and `'Hello World!'`." + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2**24" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "TMTq6N5YCJIw" + }, + "source": [ + "That's better! Make sure you use `**` any time you need to use exponents." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "w0JespP9CxHF" + }, + "source": [ + "### The assignment operator\n", + "\n", + "It is convenient to have python store and remember variables so you can use them later. You can do this with the assignment operator (`=`). Let's assign a few variables." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "dULAPQ9FCHJs" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 2 3\n" + ] + } + ], + "source": [ + "x = 1\n", + "y = 2\n", + "z = 3\n", + "print(x, y, z)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "653q09cPDx6n" + }, + "source": [ + "Here you can see that we assigned the values 1, 2, and 3 to the variables `x`, `y`, and `z` respectively. We then printed x, y, and z to see what the values were. Try assigning variables yourself. Assign 2, 4, and 8 to `a`, `b`, and `c` respectively. " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "QXwu1qgWDwPW" + }, + "outputs": [], + "source": [ + "a = 2\n", + "b = 4\n", + "c = 8" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "4lrj8FS3EhvC" + }, + "source": [ + "Notice that if you don't include a `print()` statement, running the cell doesn't return anything. That's okay though; the variables are still assigned (unless you got an error) and available for use in all other code cells. \n", + "\n", + "Now we can easily call our variables and do basic operations with them. Calculate the following:\n", + "$$ x + b $$\n", + "$$ z * c $$\n", + "$$ \\left(\\frac{b}{y}\\right) ^ z $$" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "lYA3JMNVEfzp" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "8.0" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "mk0UzyR0WnK2", - "colab_type": "code", - "colab": {} - }, - "source": [ - "type(1)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "CCa1TiLsXMi_", - "colab_type": "code", - "colab": {} - }, - "source": [ - "type(True)" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "KtBK-TNhXOdr", - "colab_type": "code", - "colab": {} - }, - "source": [ - "type('Hello World!')" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "DAle4CYJXTOd", - "colab_type": "text" - }, - "source": [ - "There are functions that let you specify the data type. `int()`, `float()`, `bool()`, and `str()` let you specify data as an integer, float, boolean, or string. Let's take a look at how this works for the `int()` function. " + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x+b\n", + "z*c\n", + "(b/y)**z" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "TyEB5EgBFnJ-" + }, + "source": [ + "Notice that only the last solution is returned. If you want all of the solutions to be returned, include print statements." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "QnTGUc1NFkaK" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "24\n", + "8.0\n" + ] + } + ], + "source": [ + "print(x+b)\n", + "print(z*c)\n", + "print((b/y)**z)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "2Mg9-mAEKPBO" + }, + "source": [ + "### Data types\n", + "In this class we will be focusing on four main data types\n", + "* string\n", + "* integer\n", + "* float\n", + "* boolean" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "V0zIo5U5MaY7" + }, + "source": [ + "#### Strings\n", + "Strings are essentially text. We used a string in our very first cell when we ran `print(\"Hello World!\")`. `\"Hello World!\"` is a string. You can assign strings to variables and utilize them, just like we did with numbers in the previous section. Here is an example:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "dT2a94G9KPk8" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "GCGCTCAAT TACTAGGCA AATCGCTAG\n" + ] + } + ], + "source": [ + "str1 = 'GCGCTCAAT'\n", + "str2 = 'TACTAGGCA'\n", + "str3 = 'AATCGCTAG'\n", + "print(str1, str2, str3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "y4btRsSXNWzb" + }, + "source": [ + "#### Integers\n", + "Integers are positive or negative whole numbers with no decimals. We have already used a few in this lesson like our variables `a`, `b`, `c`, `x`, `y`, and `z`." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Sd2NQktfN-Pa" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 4 8 1 2 3\n" + ] + } + ], + "source": [ + "print(a, b, c, x, y, z)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "7l9OhHeCOKwj" + }, + "source": [ + "#### Floats\n", + "Floats, short for floating point real values, are positive or negative numbers with decimals. You saw some when we did division. Like integers, floats can also be assigned to variables and used to do arithmetic. " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "OT1bdd10Owb1" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.2 3.0 -2.1\n", + "2.1\n" + ] + } + ], + "source": [ + "f1 = 4.2\n", + "f2 = 3.0\n", + "f3 = -2.1\n", + "print(f1, f2, f3)\n", + "print(f1+f3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "L42-ZXlERhZ7" + }, + "source": [ + "### Comparison operators\n", + "Comparison operators (>, <, ==, >=, <=) work like you would expect them to in mathematics. Let's try a few comparisons (remember to use print statements to see all of the results).\n", + "$$ 2>1 $$\n", + "$$ 4<=2 $$\n", + "$$ 5==5 $$\n", + "$$ 6>=6$$\n", + "$$ 7<3 $$" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "52io3zdvSWcr" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "print(2 > 1.5)\n", + "print(4 <= 2)\n", + "print(5 == 5.0)\n", + "print(6 >= 6)\n", + "print(7.4 < 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Each of these comparisons results in a new data type known as a Boolean." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bOSayuNbQT5j" + }, + "source": [ + "#### Booleans\n", + "\n", + "Booleans only have two values: either `True` or `False`. They are often used for comparisons, for many different types of data. As with other data types, you can assign Booleans to variables. Here are a few cases where Booleans might be useful. Can you guess the value of each comparison before running the cell?" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YT0PNRinRRmY" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "comparison1 = 2 > 1.5\n", + "print(comparison1)\n", + "comparison2 = 'This is a string' == 'This is a string'\n", + "print(comparison2)\n", + "comparison3 = '5' == 5\n", + "print(comparison3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "QGa5ZQSVGEPB" + }, + "source": [ + "### Basic functions\n", + "\n", + "We've already started using one basic function, `print()`. You may have already figured out what it does, but it prints the information inside the parentheses to the cell output. Since you have already had some practice with that. Let's explore some other basic functions. \n", + "\n", + "The function `type()` returns the data type of the argument you pass it. See the example below:" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "_o7xVv_kFzle" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "float" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "HTjA2R-mXQvm", - "colab_type": "code", - "colab": {} - }, - "source": [ - "print(int(2.1))\n", - "print(int(2.8))" - ], - "execution_count": 0, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "e6scyNgZY3-j", - "colab_type": "text" - }, - "source": [ - "Notice that both `2.1` and `2.8` result in `2` when assigned to be integers. This is because the `int()` function does not round, it just removes the decimal. \n", - "\n", - "You'll get an opportunity to learn how each of these functions work in the Exercises section. " + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(2.1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "HtkhsWOdWzie" + }, + "source": [ + "Now use `type()` to find the data type of the following objects: `1`, `True`, and `'Hello World!'`." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "mk0UzyR0WnK2" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "int" ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "YBvX1CHRZ0Di", - "colab_type": "text" - }, - "source": [ - "### Exercises\n", - "The following exercise will help you understand the concepts taught in this lesson better. It is only one problem, but covers operators, comparison, data types, and basic functions. " + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "CCa1TiLsXMi_" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "bool" ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "A86KrN-oZ8Iq", - "colab_type": "text" - }, - "source": [ - "Predict the results of the following expressions, and use python the check your answers (know that some of these may result in errors):\n", - "```\n", - "1 > 3\n", - "14 >= 2*7\n", - "\"1\" > \"3\"\n", - "bool(10) > 2\n", - "0 == False\n", - "0 == str(False)\n", - "0 == str(int(False))\n", - "str(0) == 0\n", - "True == 1**0\n", - "int(True) == str(1**0)\n", - "float(\"one\") == 1\n", - "```" + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(True)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "KtBK-TNhXOdr" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "str" ] - }, - { - "cell_type": "code", - "metadata": { - "id": "lW1bG4q8bsZw", - "colab_type": "code", - "colab": {} - }, - "source": [ - "" - ], - "execution_count": 0, - "outputs": [] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" } - ] -} \ No newline at end of file + ], + "source": [ + "type('Hello World!')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "DAle4CYJXTOd" + }, + "source": [ + "There are functions that let you specify the data type. `int()`, `float()`, `bool()`, and `str()` let you specify data as an integer, float, boolean, or string. Let's take a look at how this works for the `int()` function. " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "HTjA2R-mXQvm" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "2\n" + ] + } + ], + "source": [ + "print(int(2.1))\n", + "print(int(2.8))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "e6scyNgZY3-j" + }, + "source": [ + "Notice that both `2.1` and `2.8` result in `2` when assigned to be integers. This is because the `int()` function does **not** round, it just removes the decimal. \n", + "\n", + "You'll get an opportunity to learn how each of these functions work in the Exercises section. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YBvX1CHRZ0Di" + }, + "source": [ + "### Exercises\n", + "The following exercise will help you understand the concepts taught in this lesson better. It is only one problem, but covers operators, comparison, data types, and basic functions. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "A86KrN-oZ8Iq" + }, + "source": [ + "Predict the results of the following expressions, and use python the check your answers (know that some of these may result in errors):\n", + "```\n", + "1 > 3\n", + "14 >= 2*7\n", + "\"1\" > \"3\"\n", + "bool(10) > 2\n", + "0 == False\n", + "0 == str(False)\n", + "0 == str(int(False))\n", + "str(0) == 0\n", + "True == 1**0\n", + "int(True) == str(1**0)\n", + "float(\"one\") == 1\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "lW1bG4q8bsZw" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [], + "include_colab_link": true, + "name": "Lesson 1.ipynb", + "provenance": [], + "version": "0.3.2" + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} From 4d94857bdfe366451ef5cfb01262f07df43acfc7 Mon Sep 17 00:00:00 2001 From: Jessime Date: Thu, 6 Jun 2019 22:56:06 -0700 Subject: [PATCH 2/2] Clear outputs Diffing notebooks is hard. --- Lesson_1.ipynb | 257 ++++++++----------------------------------------- 1 file changed, 38 insertions(+), 219 deletions(-) diff --git a/Lesson_1.ipynb b/Lesson_1.ipynb index a2370f2..c041db4 100644 --- a/Lesson_1.ipynb +++ b/Lesson_1.ipynb @@ -50,21 +50,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "cz-05_Z5N-Ko" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello World!\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Hello World!\")" ] @@ -84,24 +76,13 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "W2okep-wAeLi" }, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "2+3" ] @@ -118,24 +99,13 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "CutTFG-vAx4O" }, - "outputs": [ - { - "data": { - "text/plain": [ - "160.0" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "6/2*20+100" ] @@ -152,24 +122,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "6UBGcCmtA30K" }, - "outputs": [ - { - "data": { - "text/plain": [ - "26" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "2^(24)" ] @@ -188,24 +147,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "2hgyLorIBE-u" }, - "outputs": [ - { - "data": { - "text/plain": [ - "16777216" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "2**24" ] @@ -234,21 +182,13 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "dULAPQ9FCHJs" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3\n" - ] - } - ], + "outputs": [], "source": [ "x = 1\n", "y = 2\n", @@ -268,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -298,24 +238,13 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "lYA3JMNVEfzp" }, - "outputs": [ - { - "data": { - "text/plain": [ - "8.0" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "x+b\n", "z*c\n", @@ -334,23 +263,13 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "QnTGUc1NFkaK" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n", - "24\n", - "8.0\n" - ] - } - ], + "outputs": [], "source": [ "print(x+b)\n", "print(z*c)\n", @@ -385,21 +304,13 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "dT2a94G9KPk8" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "GCGCTCAAT TACTAGGCA AATCGCTAG\n" - ] - } - ], + "outputs": [], "source": [ "str1 = 'GCGCTCAAT'\n", "str2 = 'TACTAGGCA'\n", @@ -420,21 +331,13 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "Sd2NQktfN-Pa" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2 4 8 1 2 3\n" - ] - } - ], + "outputs": [], "source": [ "print(a, b, c, x, y, z)" ] @@ -452,22 +355,13 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "OT1bdd10Owb1" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4.2 3.0 -2.1\n", - "2.1\n" - ] - } - ], + "outputs": [], "source": [ "f1 = 4.2\n", "f2 = 3.0\n", @@ -494,25 +388,13 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "52io3zdvSWcr" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n", - "False\n", - "True\n", - "True\n", - "False\n" - ] - } - ], + "outputs": [], "source": [ "print(2 > 1.5)\n", "print(4 <= 2)\n", @@ -542,23 +424,13 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "YT0PNRinRRmY" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n", - "True\n", - "False\n" - ] - } - ], + "outputs": [], "source": [ "comparison1 = 2 > 1.5\n", "print(comparison1)\n", @@ -584,24 +456,13 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "_o7xVv_kFzle" }, - "outputs": [ - { - "data": { - "text/plain": [ - "float" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type(2.1)" ] @@ -618,72 +479,39 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "mk0UzyR0WnK2" }, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type(1)" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "CCa1TiLsXMi_" }, - "outputs": [ - { - "data": { - "text/plain": [ - "bool" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type(True)" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "KtBK-TNhXOdr" }, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type('Hello World!')" ] @@ -700,22 +528,13 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "HTjA2R-mXQvm" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n", - "2\n" - ] - } - ], + "outputs": [], "source": [ "print(int(2.1))\n", "print(int(2.8))" @@ -769,7 +588,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code",