From ec7eedc0ca809aeea5a36f5451955a2d3e653a97 Mon Sep 17 00:00:00 2001 From: Jen Looper Date: Sat, 20 Nov 2021 21:35:21 -0500 Subject: [PATCH] edits --- 1_Introduction.ipynb | 105 ++++++--- 2_Functions.ipynb | 511 +++++++++++++++++++++++-------------------- README.md | 2 +- 3 files changed, 348 insertions(+), 270 deletions(-) diff --git a/1_Introduction.ipynb b/1_Introduction.ipynb index 508dfcd..5409d52 100644 --- a/1_Introduction.ipynb +++ b/1_Introduction.ipynb @@ -276,11 +276,42 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Some modules (like `math`) are built into any Python distribution while others are distributed through the centralized package repository [PyPI](http://pypi.org). You can install any package from that repository using the special operating system command `pip`. For example, the library for turtle graphics that we will see in next section is pre-installed in our notebook, but if you want to use it somewhere else, you would need the following command to install it:\n", - "```python\n", - "!pip install jturtle\n", - "```\n", - "The exclamation mark `!` in the beginning of the command means it is not a Python command, but a command for the operating system." + "Some modules (like `math`) are built into any Python distribution while others are distributed through the centralized package repository [PyPI](http://pypi.org). You can install any package from that repository using the special operating system command `pip` or, for use with Python3, `pip3`. We need to install the library for turtle graphics that we will see in the next section, so run the following command to install it:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Defaulting to user installation because normal site-packages is not writeable\n", + "Collecting jturtle\n", + " Using cached jturtle-0.0.3-py3-none-any.whl (4.1 kB)\n", + "Requirement already satisfied: matplotlib in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from jturtle) (3.5.0)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (4.28.1)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (1.3.2)\n", + "Requirement already satisfied: pillow>=6.2.0 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (8.4.0)\n", + "Requirement already satisfied: numpy>=1.17 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (1.21.4)\n", + "Requirement already satisfied: setuptools-scm>=4 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (6.3.2)\n", + "Requirement already satisfied: cycler>=0.10 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (0.11.0)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (2.8.2)\n", + "Requirement already satisfied: pyparsing>=2.2.1 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (2.4.7)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from matplotlib->jturtle) (21.2)\n", + "Requirement already satisfied: six>=1.5 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from python-dateutil>=2.7->matplotlib->jturtle) (1.16.0)\n", + "Requirement already satisfied: setuptools in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from setuptools-scm>=4->matplotlib->jturtle) (59.1.1)\n", + "Requirement already satisfied: tomli>=1.0.0 in /Users/jenniferlooper/Library/Python/3.8/lib/python/site-packages (from setuptools-scm>=4->matplotlib->jturtle) (1.2.2)\n", + "Installing collected packages: jturtle\n", + "Successfully installed jturtle-0.0.3\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install jturtle" ] }, { @@ -289,26 +320,27 @@ "source": [ "### Turtle Graphics\n", "\n", - "The library we have just installed allows us to use some simple drawing commands --- so-called **Turtle graphics**. Those commands control an imaginary *turtle*, which can move across the screen, turn around, and so on --- leaving the trace behind. For example, if I want to draw a triangle, I can use the following commands:" + "The library we have just installed allows us to use some simple drawing commands: so-called **Turtle graphics**. Those commands control an imaginary *turtle*, which can move across the screen, turn around, and so on, leaving the trace behind. For example, if I want to draw a triangle, I can use the following commands:" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": { "trusted": true }, "outputs": [ { - "ename": "ModuleNotFoundError", - "evalue": "No module named 'jturtle'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/m5/_8096psx5dn9lt75fj85cc380000gn/T/ipykernel_15802/3908673822.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mjturtle\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mturtle\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mturtle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mturtle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mright\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m120\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mturtle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mturtle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mright\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m120\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'jturtle'" - ] + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAPx0lEQVR4nO3defCdZXnG8e8VwhICstSIQFXGwULCFvbFIgrSFrEWpQqlVattseoUSiAgFuugIvuqsggDAqIie8tW9sWwyhYCgVTWMrWLTAHZt6t/PAfEmPyS/PI753nOOddnhhlmMnDuf6689/O+9/2+sk1EtGdc7QIiYt4SzohGJZwRjUo4IxqVcEY0KuGMaFTCGdGohDOiUQlnRKMSzohGJZwRjUo4IxqVcEY0KuGMaFTCGdGohDOiUQlnRKMSzohGJZwRjUo4IxqVcEY0KuGMaFRPwilp+V78TsQg6Xo4Ja0NPCPpy5LGd/v3IgZF18Np+4HOv+4M3C1pu27/ZsQgUC/e+C7JlL8IdgKOBO4B9rH9UNd/PKJP9eyGkIsLgCnAbcCtkg7JeTRi3np+t9b2i7YPBtYH3gk8KOmvJeXOccRb9Kytta35/NlmwLHAeGBP2zd1vaCIPlA9nJ0/Hwf8BXAocD2wn+0nul5YRMOaaCVtv277LGBt4GHgHklfkzShcmkR1TQRzjfYftb214BNKGfS2ZI+KWm+V92IQdVEWzvCf7cN5Tz6DOU8eteYFxfRqKaunHOzfT2wMfBD4DJJ35f0jsplRfRE0+EEsP2a7e9TzqPPAvdJmiZpqcqlRXRV8+F8g+2nbE8DtgY+DNwracecR2NQNX3mXMD/8yPAUcAjwDTbs8fy/x9RW99cOedm+1LKHd0rgBskHS1ppcplRYyZvg0ngO2XbR9NmdedADwg6e8lLVG5tI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rZW0qqQfABcBJwObJZgRFcMpaRlJXwHuBf6LMnJ3Wla5Ioqet7Wdc+VOlFWue4EtbP+i13VEtK6n4ZS0HuXVk6sAX7B9VS9/P6Kf9KytlfQ94GrgfMpd2AQzYgRdv3J2BtQBXqc8r3yy278ZMQjU7ef6ksYBr9lWV38oYsB0PZwRMTrVn3NGxLwlnBGNSjgjGpVwRjQq4YxoVMIZ0aiEM6JRCWdEoxLOiEYlnBGNSjgjGpVwRjQq4YxoVMIZ0aiEM6JRCWdEoxLOiEYlnBGNSjgjGpVwRjQq4YxoVMIZ0aiEM6JR/w8Rmw8FTOeteQAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" } ], "source": [ @@ -326,29 +358,31 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "First of all, the command `import jturtle as turtle` imports the module, and changes the name to `turtle` --- this name sounds a bit nicer. If you want to save on typing, you can say `import jturtle as T`, and use `T` instead of `turtle`.\n", + "First of all, the command `import jturtle as turtle` imports the module and changes the name to `turtle` (this name sounds a bit nicer). \n", + "\n", + "> If you want to save on typing, you can say `import jturtle as T`, and use `T` instead of `turtle`.\n", "\n", "Commands like `turtle.forward` tell turtle to do something. The most important commands are:\n", - " * `turtle.forward(n)` -- move `n` units forward\n", - " * `turtle.backward(n)` -- move `n` units backwards\n", + " \n", + " * `turtle.forward(n)` -- move `n` units forward (the turtle moves up)\n", + " * `turtle.backward(n)` -- move `n` units backwards (the turtle moves down)\n", " * `turtle.left(n)` and `turtle.right(n)` -- turn `n` degrees left or right\n", - " * `turtle.penup()` and `turtle.pendown()` allows to control whether turtle leaves the trace behind or not. You need to use those commands if you want to draw several figures not connected to each other\n", + " * `turtle.penup()` and `turtle.pendown()` allows you to control whether the turtle leaves the trace behind or not. You need to use those commands if you want to draw several figures not connected to each other\n", " * `turtle.done()` tells the turtle that the drawing is over, and it should be displayed on the screen\n", " \n", - " If you want to see how the drawing was created step-by-step, you can use `turtle.done(step_by_step=True)`, or just `turtle.done(True)`:" + " > If you want to see how the drawing was created step-by-step, you can use `turtle.done(step_by_step=True)`, or just `turtle.done(True)`:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "trusted": true }, "outputs": [ { "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAABXCAYAAACnZJZlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAABfUlEQVR4nO3cMY5CMQxAQYy4/5VNvdJuBbygvzMHiCwrekWKzO7eAGjcTw8A8J+ILkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXIPR49YCZ2d2ddwzDTzNz6c+OT98b+/0cu/3by9Hls06H6equut9viJ7d/s7zAkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChB6nBwCuaWb29AzfaHbtBaDieQEgJLoAIdEFCIkuQEh0AUKiCxASXYCQ6AKERBcgJLoAIdEFCIkuQEh0AUKiCxB6AnLpIq3t6lghAAAAAElFTkSuQmCC", - "image/svg+xml": "\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAABXCAYAAACnZJZlAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAABf0lEQVR4nO3cQYrCQBBA0ZR4/yuXCw8wIvojk/f2DUURfkMvMrt7ANC4nT0AwJWILkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQur9zaGZ2d+fTw/A0M5f7C1H1PV1xt8fR7NduX/NWdPk+l9r3XG23ZQzt9m+eFwBCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2AkOgChEQXICS6ACHRBQiJLkBIdAFCogsQEl2A0P3sAYD/Y2b27Bl+3ezaEUDF8wJASHQBQqILEBJdgJDoAoREFyAkugAh0QUIiS5ASHQBQqILEHoAau4irQdpshUAAAAASUVORK5CYII=", "text/plain": [ "
" ] @@ -360,14 +394,21 @@ } ], "source": [ + "# go up\n", "turtle.forward(100)\n", + "# turn right\n", "turtle.right(90)\n", + "# go forward\n", "turtle.forward(100)\n", + "# turn right\n", "turtle.right(90)\n", + "# go down\n", "turtle.forward(100)\n", + "# turn right\n", "turtle.right(90)\n", + "# go left\n", "turtle.forward(100)\n", - "turtle.right(90)\n", + "# show each step separately\n", "turtle.done(True)" ] }, @@ -379,19 +420,23 @@ "source": [ "Here, we can see that the turtle first moved up 100 points, then turned right, went forward for another 100 points, and so on. Repeating those actions 4 times we end up with a square.\n", "\n", - "Those were very simple drawings, but as we will see later --- computers are very good at repeating and composing together simple steps to get more complex results. We will see some examples of very beautiful drawings created using the same approach of turtle graphics." + "Those were very simple drawings, but as we will see later, computers are very good at repeating and composing together simple steps to get more complex results. We will see some examples of very beautiful drawings created using the same approach of turtle graphics." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### An Exercise\n", + "## 🚀 Challenges\n", "\n", - "Before going to the next chapter, we want you to do a couple of simple exercices for me.\n", + "Before going to the next chapter, try one of these challenges.\n", "\n", - "1. Suppose you put a certain amount of money into a bank deposit (say, \\$100). This amount increases at the rate 2.5% per year. Calculate the amount that you will have after 1, 2 and 3 years.\n", - "2. To practice turtle graphics, please draw a simple house, like the one shown below. Please, note that in order to move the turtle without leaving a trace, you need to execute `turtle.penup()` command.\n", + "### A Math Challenge\n", + "Suppose you put a certain amount of money into a bank deposit (say, \\$100). This amount increases at the rate 2.5% per year. Calculate the amount that you will have after 1, 2 and 3 years.\n", + "\n", + "### An Art Challenge \n", + "\n", + "To practice turtle graphics, draw a simple house, like the one shown below. Please, note that in order to move the turtle without leaving a trace, you need to execute `turtle.penup()` command.\n", "\n", "![Simple House](./images/house.png)" ] diff --git a/2_Functions.ipynb b/2_Functions.ipynb index ed6b766..01d7f71 100644 --- a/2_Functions.ipynb +++ b/2_Functions.ipynb @@ -1,10 +1,10 @@ { "cells": [ { + "cell_type": "markdown", "metadata": { "collapsed": true }, - "cell_type": "markdown", "source": [ "# Introduction to Programming with Python\n", "\n", @@ -14,29 +14,44 @@ ] }, { + "cell_type": "code", + "execution_count": 1, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "import jturtle as turtle" - ], - "execution_count": 1, - "outputs": [] - }, - { - "metadata": {}, - "cell_type": "markdown", - "source": [ - "To simplify writing, let us use a variable `size` to represent the size of the house. First thing we need to do is to draw a square:" ] }, { - "metadata": { - "trusted": true, - "scrolled": true - }, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the last challenge, did you notice yourself writing a lot of the same numbers repeatedly? You can save typing by using a variable. Create one named 'size' to represent the size of the house. The first thing we need to do is to draw a square:" + ] + }, + { "cell_type": "code", + "execution_count": 3, + "metadata": { + "scrolled": true, + "trusted": true + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC2klEQVR4nO3cwQ3DIBAAQV/k/lu+NJCv8SqaKYCDxwpezO5eQM/n7Q0Av4kTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcEHWfGDIzPsflL+3uPLX2kTiv69lDwBuevnQ8ayFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRN2nBs3MnpoF/2B2NQNFnrUQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFC1BcH9hDP2xJZHgAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "size=120\n", "turtle.forward(size)\n", @@ -48,33 +63,35 @@ "turtle.forward(size)\n", "turtle.right(90)\n", "turtle.done()" - ], - "execution_count": 2, - "outputs": [ - { - "output_type": "display_data", - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAAyxJREFUeJzt3cEJwzAQAEFfcP8tX5qIEfHOFCAOgVbopdndC+j6nB4AOEsEIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO4+PcAvzYxPFHil3Z2n1n5VBK7r2c2CE56+3DwHIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO4+PcCvzcyengH+yew6M1DmOQBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxX5PAEPHBIswIAAAAAElFTkSuQmCC\n", - "text/plain": "
" - }, - "metadata": { - "needs_background": "light" - } - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ - "Now, after drawing the main square, let us draw the roof. After the code above, the turtle is in the low left corner of the square, so we need to move up, and then draw a triangle:" + "Now, after drawing the main square, let's draw the roof. After the code above, the turtle is in the lower left corner of the square, so we need to move up and then draw a triangle:" ] }, { + "cell_type": "code", + "execution_count": 8, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQq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zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0dtq4DJal1HUvaBqmyGakj39ZKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpN/TcYlq2CRkXLBQAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "turtle.forward(size)\n", "turtle.right(90)\n", @@ -92,33 +109,35 @@ "turtle.forward(size)\n", "turtle.right(120)\n", "turtle.done()" - ], - "execution_count": 3, - "outputs": [ - { - "output_type": "display_data", - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAACyVJREFUeJzt3XvQrWVZx/HvD8hCLU9FThlOM2gqyEHZWaZ4YBgRZsQTJLtoMGSkTEkcQeVQaioeMMhxrJgh8zA4OONYOnjKMmTA0khTFGvKpqymJsuMyCi9+uNZ5Y44vIe11r3Wur6fP9nvu9a193757vt51vM8d6oKSX3tN3oASWMZAak5IyA1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IDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnMHjB5g3pLU6BmkdZIq/5+ROvNwQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJz/w27Uq2k03mw/gAAAABJRU5ErkJggg==\n", - "text/plain": "
" - }, - "metadata": { - "needs_background": "light" - } - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ - "Finally, to draw a window, we need to put the pen up to stop drawing, move 2/3 of the `size` down and 1/3 left, and draw a smaller square:" + "Finally, to draw a window, we need to raise the pen up to stop drawing, move 2/3 of the `size` down and 1/3 left, and draw a smaller square:" ] }, { + "cell_type": "code", + "execution_count": 9, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKzklEQVR4nO3de6xlZ1nH8e+vrWgBRUCRKJaQFARaeoGOKEK5NA2lTSi3VjpaUywNBYRKCS3QiwIC5VJsJQSlSUWBlJSEqJAKIoqlaVGw3KFoFKOo0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JOqSnjlJoyTqkp45SaMk6pKeOUmjJOqSnjlJoyTqkp45SaMk6pKeOUmjJOqalZPQLQx/BpncwmTh9cq3Xjaa3UlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafU1Mqez+mDa6WtSZXNSB15Wis1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTX136dCuYp+M3rUAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "# Draw a square\n", "turtle.forward(size)\n", @@ -156,24 +175,11 @@ "turtle.right(90)\n", "\n", "turtle.done()" - ], - "execution_count": 4, - "outputs": [ - { - "output_type": "display_data", - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAC0NJREFUeJzt3XuwrXVdx/H3B8hCLW9FThlOM2gqyEU5WaZ4YRgRZsQbJKdoMGSkTEkcQeVSaipeMMhxrJgh8zI4OONYOnjLMmTA0khTFGvKpqymJsuMyCj99sezyhNx2Ze11m+t9X2//jxn77W++5y93/v3PGs9zy9VhaS+9hs9gKSxjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRmBFZLkfknuNnoO9WIEVkSSAJ8Grhg9i3ox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QmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==\n", - "text/plain": "
" - }, - "metadata": { - "needs_background": "light" - } - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "You can notice that as the program becomes rather big, it is also getting more difficult to understand. One thing to simplify understanding a program is by using **comments**. Comments are pieces of text that can be embedded into the program, and which are ignored by Python. Anything that starts with `#` sign and until the end of line is considered a comment, and is discarded.\n", "\n", @@ -185,8 +191,8 @@ ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Introducing Functions\n", "\n", @@ -196,10 +202,12 @@ ] }, { + "cell_type": "code", + "execution_count": 19, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "def square(x):\n", " turtle.forward(x)\n", @@ -210,43 +218,43 @@ " turtle.right(90)\n", " turtle.forward(x)\n", " turtle.right(90)" - ], - "execution_count": 19, - "outputs": [] + ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "When we run this code, nothing is drawn on the screen --- we just specify the list of commands that comprise a function. However, once the cell above has been executed, Python gets to know a new command `square`. To actually draw a square we need to **call** this function:" ] }, { + "cell_type": "code", + "execution_count": 21, "metadata": { "trusted": true }, - "cell_type": "code", - "source": [ - "square(100)\n", - "turtle.done()" - ], - "execution_count": 21, "outputs": [ { - "output_type": "display_data", "data": { - "image/png": "iVBORw0KGgoAAAAN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SJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMTdpwf4tJnZ0zPAP5ldZwbKPAcgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQg7g2jwBDx4wvyuAAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] }, "metadata": { "needs_background": "light" - } + }, + "output_type": "display_data" } + ], + "source": [ + "square(100)\n", + "turtle.done()" ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Because we need to draw squares of different sizes, this function has one **argument**, or **parameter**. It is denoted by `(x)` after the function's name, and it is in fact a kind of variable, which takes the value that is passed to the function during the call. In the case above, we have called the function `square(100)`, so in the functions's body variable `x` will be equal to 100. We can use any expression in place of a parameter, for example `square(size/2+10)` would be a perfectly valid call. Expression `size/2+10` would be computed, and the result associated with parameter `x`. When defining a function you always use some names in place of parameters, which will act as \"placeholders\" - you cannot use expressions. \n", "\n", @@ -254,10 +262,25 @@ ] }, { + "cell_type": "code", + "execution_count": 24, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAh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sTERAEiyOV/MGquqjJ5BW3fA6AHmzW/AsQzx+tm0cwKStskISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1NzGbU0+2ipsze327NoOI7AAI38IVyFCWi8eDkjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCac2vyBXB7cK0TIzBnVZXRM0jb4eGA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "square(size)\n", "\n", @@ -277,40 +300,27 @@ "square(size/3)\n", "\n", "turtle.done()" - ], - "execution_count": 24, - "outputs": [ - { - "output_type": "display_data", - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmU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ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1NzGbU0+2ipsze327NoOI7AAI38IVyFCWi8eDkjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCac2vyBXB7cK0TIzBnVZXRM0jb4eGA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==\n", - "text/plain": "
" - }, - "metadata": { - "needs_background": "light" - } - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Inside functions we can of course call other functions. As a simple exercise, please take the code that draws a house above, and turn it into a function with one parameter -- the size of the house. Put your code in the cell below, and test it:" ] }, { + "cell_type": "code", + "execution_count": null, "metadata": { "trusted": true }, - "cell_type": "code", - "source": [], - "execution_count": null, - "outputs": [] + "outputs": [], + "source": [] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "If you did not succeed, or if you are getting some syntax errors, take a note of the following:\n", "\n", @@ -320,8 +330,8 @@ ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Blocks and Line Indentation\n", "\n", @@ -354,8 +364,8 @@ ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Functions that Return a Value\n", "\n", @@ -365,21 +375,21 @@ ] }, { + "cell_type": "code", + "execution_count": 25, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "def interest(amount, rate):\n", " x = amount * (1+rate/100)\n", " return x" - ], - "execution_count": 25, - "outputs": [] + ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "In this function, `amount` is the amount of money we currently have, and `rate` is the yearly interest rate in percents. We calculate the amount after one year and denote it by `x`, and then return this value using the `return` statement.\n", "\n", @@ -387,80 +397,86 @@ ] }, { + "cell_type": "code", + "execution_count": 26, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "102.49999999999999\n" + ] + } + ], "source": [ "result = interest(100, 2.5)\n", "print(result)" - ], - "execution_count": 26, - "outputs": [ - { - "output_type": "stream", - "text": "102.49999999999999\n", - "name": "stdout" - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "We can also directly use `interest` in any expression, for example, just to print the amount in one year, we can write" ] }, { + "cell_type": "code", + "execution_count": 27, "metadata": { "trusted": true }, - "cell_type": "code", - "source": [ - "interest(100, 2.5)" - ], - "execution_count": 27, "outputs": [ { - "output_type": "execute_result", - "execution_count": 27, "data": { - "text/plain": "102.49999999999999" + "text/plain": [ + "102.49999999999999" + ] }, - "metadata": {} + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" } + ], + "source": [ + "interest(100, 2.5)" ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "And to calculate the resulting amount in two years:" ] }, { + "cell_type": "code", + "execution_count": 28, "metadata": { "trusted": true }, - "cell_type": "code", - "source": [ - "interest(interest(100, 2.5),2.5)" - ], - "execution_count": 28, "outputs": [ { - "output_type": "execute_result", - "execution_count": 28, "data": { - "text/plain": "105.06249999999997" + "text/plain": [ + "105.06249999999997" + ] }, - "metadata": {} + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" } + ], + "source": [ + "interest(interest(100, 2.5),2.5)" ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Local and Global Variables\n", "\n", @@ -470,10 +486,20 @@ ] }, { + "cell_type": "code", + "execution_count": 30, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "107.68906249999996\n" + ] + } + ], "source": [ "interest_rate = 2.5\n", "\n", @@ -481,19 +507,11 @@ " return x * (1+interest_rate/100)\n", "\n", "print(interest(interest(interest(100))))" - ], - "execution_count": 30, - "outputs": [ - { - "output_type": "stream", - "text": "107.68906249999996\n", - "name": "stdout" - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Tuples\n", "\n", @@ -503,105 +521,121 @@ ] }, { + "cell_type": "code", + "execution_count": 31, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "point = (0,10)" - ], - "execution_count": 31, - "outputs": [] + ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "To access individual coordinates of a point, we can use the notation `point[0]` and `point[1]`:" ] }, { + "cell_type": "code", + "execution_count": 32, "metadata": { "trusted": true }, - "cell_type": "code", - "source": [ - "print(\"Our coordinates are: x=\",point[0],', y=',point[1])" - ], - "execution_count": 32, "outputs": [ { + "name": "stdout", "output_type": "stream", - "text": "Our coordinates are: x= 0 , y= 10\n", - "name": "stdout" + "text": [ + "Our coordinates are: x= 0 , y= 10\n" + ] } + ], + "source": [ + "print(\"Our coordinates are: x=\",point[0],', y=',point[1])" ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Another way to decompose a tuple into parts is assigning it to a pair of variables. You can write:" ] }, { + "cell_type": "code", + "execution_count": 33, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Our coordinates are: x= 0 , y= 10\n" + ] + } + ], "source": [ "x,y = point\n", "print(\"Our coordinates are: x=\",x,', y=',y)" - ], - "execution_count": 33, - "outputs": [ - { - "output_type": "stream", - "text": "Our coordinates are: x= 0 , y= 10\n", - "name": "stdout" - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "By the way, using tuples you can write nice assignments for several variables at once, for example" ] }, { + "cell_type": "code", + "execution_count": 34, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "x,y = 0,10\n", "x+y" - ], - "execution_count": 34, - "outputs": [ - { - "output_type": "execute_result", - "execution_count": 34, - "data": { - "text/plain": "10" - }, - "metadata": {} - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Coming back to the interest rate example, we can return total amount and accumulated interest using a tuple:" ] }, { + "cell_type": "code", + "execution_count": 35, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "102.5 2.5\n" + ] + } + ], "source": [ "def interest(x,rate):\n", " acc = x*rate/100\n", @@ -609,19 +643,11 @@ "\n", "total, acc = interest(100,2.5)\n", "print(total,acc)" - ], - "execution_count": 35, - "outputs": [ - { - "output_type": "stream", - "text": "102.5 2.5\n", - "name": "stdout" - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## Another Style of Drawing\n", "\n", @@ -637,56 +663,58 @@ ] }, { + "cell_type": "code", + "execution_count": 5, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "def square(x1,y1,x2,y2):\n", " turtle.line((x1,y1),(x1,y2))\n", " turtle.line((x1,y1),(x2,y1))\n", " turtle.line((x2,y2),(x1,y2))\n", " turtle.line((x2,y2),(x2,y1))" - ], - "execution_count": 5, - "outputs": [] + ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Using this function, we can draw a house:" ] }, { + "cell_type": "code", + "execution_count": 7, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAABMBJREFUeJzt2K2OpFUYRtFzyBCCIUFiEdwEnqsAMQ7PpZCgUQiCwnAtaBwBLAnmoEhmPjrQ01Nd389eS5d4k6pnJ6fmWmsAXe/sfQCwLxGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBEImXN+Mud8b+87OBYRCJhzfjjn/GGM8fMY448555d738RxiMCFvTL+38YYn44xXo4xvh9jfD3n/F0MGEMELumB8X+x1vporfXtWuvlGOODMcaPQwwYInAp/zH+71793FrrTzHgHyJwAY8d/5YYMIYInNpTx78lBm0icEK3Gv+WGDSJwIk81/i3xKBFBE7gXuPfEoMGETiwvca/JQbXJgIHdJTxb4nBNYnAgRx1/FticC0icABnGf+WGFyDCOzorOPfEoNzE4EdXGX8W2JwTiJwR1cd/5YYnIsI3EFl/FticA4i8Iyq498Sg2MTgWdg/A8Tg2MSgRsy/scRg2MRgRsw/qcRg2MQgbdg/LchBvsSgScw/uchBvsQgTdg/PchBvclAo9g/PsQg/sQgf9g/McgBs9LBB5g/MckBs9DBF5h/OcgBrclAsP4z0oMbiMdAeO/BjF4O8kIGP81icHTpCJg/A1i8GYSETD+JjF4nEtHwPgZQwz+zyUjYPw8RAwedqkIGD+PIQavm2utvW+4iTnnZ2OMn8YYv44xvjJ8HmvO+f4Y45sxxudjjF/WWh/vfNJdXSkC744x/tr7Ds5vrTX3vuGeLhOBMcaYc67aF8htFX9Dl/pPAHhzIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxL/Y+gNfNOdfeN7yttdbc+wYeTwQO6MwjukLEajwHIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO7F3gfwb3POtfcNdIjAway15t430OI5AHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEv9j7g1uaca+8b4EzmWjYDZZ4DECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCEPc33Gm/GI8qlCkAAAAASUVORK5CYII=", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "square(0,0,120,120)\n", "square(40,40,80,80)\n", "turtle.line((0,120),(60,150))\n", "turtle.line((60,150),(120,120))\n", "turtle.done()" - ], - "execution_count": 7, - "outputs": [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xIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxL/Y+gNfNOdfeN7yttdbc+wYeTwQO6MwjukLEajwHIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO7F3gfwb3POtfcNdIjAway15t430OI5AHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEiAHEv9j7g1uaca+8b4EzmWjYDZZ4DECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCECcCEPc33Gm/GI8qlCkAAAAASUVORK5CYII=\n", - "text/plain": "
" - }, - "metadata": { - "needs_background": "light" - } - } ] }, { - "metadata": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "## An Exercise\n", "\n", @@ -715,57 +743,62 @@ ] }, { + "cell_type": "code", + "execution_count": 13, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": [ + "4.0" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import math\n", "math.sqrt(16)" - ], - "execution_count": 13, - "outputs": [ - { - "output_type": "execute_result", - "execution_count": 13, - "data": { - "text/plain": "4.0" - }, - "metadata": {} - } ] }, { + "cell_type": "code", + "execution_count": null, "metadata": { "trusted": true }, - "cell_type": "code", + "outputs": [], "source": [ "# Write your solution here" - ], - "execution_count": null, - "outputs": [] + ] } ], "metadata": { + "interpreter": { + "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" + }, "kernelspec": { - "name": "python36", "display_name": "Python 3.6", - "language": "python" + "language": "python", + "name": "python3" }, "language_info": { - "mimetype": "text/x-python", - "nbconvert_exporter": "python", - "name": "python", - "pygments_lexer": "ipython3", - "version": "3.6.6", - "file_extension": ".py", "codemirror_mode": { - "version": 3, - "name": "ipython" - } + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.9" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/README.md b/README.md index d8c32f2..156efe9 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ If Python and pip are installed a version number will be displayed, such as *3.8 ### Visual Studio Code -The instructions for this workshop assume you are using [Visual Studio Code](https://code.visualstudio.com?WT.mc_id=academic-49102-chrhar), an open source code editor. You will also need the [Pylance extension](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance&WT.mc_id=academic-49102-chrhar), which will provide additional functionality when writing Python. +The instructions for this workshop assume you are using [Visual Studio Code](https://code.visualstudio.com?WT.mc_id=academic-50029-jelooper), an open source code editor. You will also need the [Jupyter extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter&WT.mc_id=academic-50029-jelooper), which will provide additional functionality when writing Python. * Use [GitHub Codespaces](https://github.com/features/codespaces). Currently you need to apply for early access to this technology and there may be costs involved in using it, but it works well with Python. * Use **Binder** by clicking on the button at the top of this page. Keep in mind that when using Binder all changes you make to notebooks are not saved by default, and the environment tends to expire after some time - thus it is very easy to lose your work.