edits
This commit is contained in:
Родитель
61c09446c4
Коммит
ec7eedc0ca
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": true
|
"collapsed": true
|
||||||
},
|
},
|
||||||
"cell_type": "markdown",
|
|
||||||
"source": [
|
"source": [
|
||||||
"# Introduction to Programming with Python\n",
|
"# Introduction to Programming with Python\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -14,29 +14,44 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import jturtle as turtle"
|
"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": {
|
"cell_type": "markdown",
|
||||||
"trusted": true,
|
"metadata": {},
|
||||||
"scrolled": true
|
"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",
|
"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": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"size=120\n",
|
"size=120\n",
|
||||||
"turtle.forward(size)\n",
|
"turtle.forward(size)\n",
|
||||||
|
@ -48,33 +63,35 @@
|
||||||
"turtle.forward(size)\n",
|
"turtle.forward(size)\n",
|
||||||
"turtle.right(90)\n",
|
"turtle.right(90)\n",
|
||||||
"turtle.done()"
|
"turtle.done()"
|
||||||
],
|
|
||||||
"execution_count": 2,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAAyxJREFUeJzt3cEJwzAQAEFfcP8tX5qIEfHOFCAOgVbopdndC+j6nB4AOEsEIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO4+PcAvzYxPFHil3Z2n1n5VBK7r2c2CE56+3DwHIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO4+PcCvzcyengH+yew6M1DmOQBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxIgBxX5PAEPHBIswIAAAAAElFTkSuQmCC\n",
|
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"needs_background": "light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKtElEQVR4nO3de9BtdV3H8fcHyEItU8ucMhxn0FSQi3KyTPHCMCLMiKmQnKLBkJEyJXEElUupqXjBIMexZIYsc3Bwxql0SDPLkAFLI80b1pRNWU1NdjEio/TbH2unJzqnc9t7/757r/frT85z9vryzHk/v73Xs9ZvpaqQ1M8howeQtHvGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZz7IMl9k9xt9ByaF+PciyQBPg5cO3gUzYxx7t1pwJ3AKUnuP3oYzUfc8X3PFm9lPw08HzgJuE9VnTt2Ks3FYaMHaO4FwOeq6n1JbgFuS3JCVX1s9GDafq6ce5DkO5hWzcdU1Z8s/tu5wI8Bjy2/cVoxP3Pu2auAX/6fMBfeBhwOPGvIRJoVV87dSPJI4AbgoVX1z3f5s8cB71j82R0DxtNMuHLexeJXJ1cDl901TICq+jBwM3DRmkfTzLhy3kWSHwJeApxQVV/Zw9ccAfwRcHxV/eU659N8GOcuktwd+CxwdlXduJev/Rmmt7Z+/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
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"turtle.forward(size)\n",
|
"turtle.forward(size)\n",
|
||||||
"turtle.right(90)\n",
|
"turtle.right(90)\n",
|
||||||
|
@ -92,33 +109,35 @@
|
||||||
"turtle.forward(size)\n",
|
"turtle.forward(size)\n",
|
||||||
"turtle.right(120)\n",
|
"turtle.right(120)\n",
|
||||||
"turtle.done()"
|
"turtle.done()"
|
||||||
],
|
|
||||||
"execution_count": 3,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAACyVJREFUeJzt3XvQrWVZx/HvD8hCLU9FThlOM2gqyEHZWaZ4YBgRZsQTJLtoMGSkTEkcQeVQaioeMMhxrJgh8zA4OONYOnjKMmTA0khTFGvKpqymJsuMyCi9+uNZ5Y44vIe11r3Wur6fP9nvu9a193757vt51vM8d6oKSX3tN3oASWMZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwIrJMn9ktxt9BzqxQisiCQBPg1cMXoW9WIEVseJwK3A8UnuP3oY9RF3IBpvdghwI/B84FjgvlV1xtip1MUBowcQAC8AvlhVH0xyPXBTkqOr6lOjB9PmcyUwWJLvZVoFPLqq/nT2384Afhp4TPkXpAXznMB4rwJ+838CMPNW4EDgWUMmUiuuBAZK8gjgauAhVfXV2/zaY4F3zn7tlhHzqQdXAoPMPhK8DLjwtgEAqKqPA9cB5y57NvXi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ak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJz/w27Uq2k03mw/gAAAABJRU5ErkJggg==\n",
|
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"needs_background": "light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKzklEQVR4nO3de6xlZ1nH8e+vrWgBRUCRKJaQFARaeoGOKEK5NA2lTSi3VjpaUywNBYRKCS3QiwIC5VJsJQSlSUWBlJSEqJAKIoqlaVGw3KFoFKOo0YgXrBXL5fGPtYWxzjhzZs7e77P3+n7+7JzZ6+nJfM+79jprvytVhaR+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mjJOqalZPQLQx/BpncwmTh9cq3Xjaa3UlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafUlHFKTRmn1JRxSk0Zp9SUcUpNGafU1Mqez+mDa6WtSZXNSB15Wis1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTVlnFJTxik1ZZxSU8YpNWWcUlPGKTX136dCuYp+M3rUAAAAAElFTkSuQmCC",
|
||||||
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"# Draw a square\n",
|
"# Draw a square\n",
|
||||||
"turtle.forward(size)\n",
|
"turtle.forward(size)\n",
|
||||||
|
@ -156,24 +175,11 @@
|
||||||
"turtle.right(90)\n",
|
"turtle.right(90)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"turtle.done()"
|
"turtle.done()"
|
||||||
],
|
|
||||||
"execution_count": 4,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAC0NJREFUeJzt3XuwrXVdx/H3B8hCLW9FThlOM2gqyEU5WaZ4YRgRZsQbJKdoMGSkTEkcQeVSaipeMMhxrJgh8zI4OONYO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DkjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCac2vyBXB7cK0TIzBnVZXRM0jb4eGA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==\n",
|
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"needs_background": "light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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",
|
"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",
|
"\n",
|
||||||
|
@ -185,8 +191,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Introducing Functions\n",
|
"## Introducing Functions\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -196,10 +202,12 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def square(x):\n",
|
"def square(x):\n",
|
||||||
" turtle.forward(x)\n",
|
" turtle.forward(x)\n",
|
||||||
|
@ -210,43 +218,43 @@
|
||||||
" turtle.right(90)\n",
|
" turtle.right(90)\n",
|
||||||
" turtle.forward(x)\n",
|
" turtle.forward(x)\n",
|
||||||
" turtle.right(90)"
|
" turtle.right(90)"
|
||||||
],
|
]
|
||||||
"execution_count": 19,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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:"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"square(100)\n",
|
|
||||||
"turtle.done()"
|
|
||||||
],
|
|
||||||
"execution_count": 21,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
"data": {
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAAy1JREFUeJzt3dEJAyEQQMHbcP23vGkiieTeTAGyCD7xy9ndC+h6nR4AOEsEIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIE4EIO4+PcAnzYxPFHic3Z1vrv+oCFzX9zcMfukXF5vnAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJA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AMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMSJAMTdpwf4tJnZ0zPAP5ldZwbKPAcgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQgTgQg7g2jwBDx4wvyuAAAAABJRU5ErkJggg==",
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"needs_background": "light"
|
"needs_background": "light"
|
||||||
}
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"square(100)\n",
|
||||||
|
"turtle.done()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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",
|
"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",
|
"\n",
|
||||||
|
@ -254,10 +262,25 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 24,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAC0NJREFUeJzt3XuwrXVdx/H3B8hCLW9FThlOM2gqyEU5WaZ4YRgRZsQbJKdoMGSkTEkcQeVSaipeMMhxrJgh8zI4OONYOnjLMmTA0khTFGvKpq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pOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCac2vyBXB7cK0TIzBnVZXRM0jb4eGA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==",
|
||||||
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"square(size)\n",
|
"square(size)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -277,40 +300,27 @@
|
||||||
"square(size/3)\n",
|
"square(size/3)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"turtle.done()"
|
"turtle.done()"
|
||||||
],
|
|
||||||
"execution_count": 24,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+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zW/AsQzx+tm0cwKStskISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1NzGbU0+2ipsze327NoOI7AAI38IVyFCWi8eDkjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCac2vyBXB7cK0TIzBnVZXRM0jb4eGA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDV3wOgB5i1JjZ5BWiep8mdG6szDAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjNGQGpOSMgNWcEpOaMgNScEZCaMwJSc0ZAas4ISM0ZAak5IyA1ZwSk5oyA1JwRkJozAlJzRkBqzghIzRkBqTkjIDVnBKTmjIDUnBGQmjMCUnNGQGrOCEjN/Tem07msqxN4lwAAAABJRU5ErkJggg==\n",
|
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"needs_background": "light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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:"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [],
|
"source": []
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"If you did not succeed, or if you are getting some syntax errors, take a note of the following:\n",
|
"If you did not succeed, or if you are getting some syntax errors, take a note of the following:\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -320,8 +330,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Blocks and Line Indentation\n",
|
"## Blocks and Line Indentation\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -354,8 +364,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Functions that Return a Value\n",
|
"## Functions that Return a Value\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -365,21 +375,21 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 25,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def interest(amount, rate):\n",
|
"def interest(amount, rate):\n",
|
||||||
" x = amount * (1+rate/100)\n",
|
" x = amount * (1+rate/100)\n",
|
||||||
" return x"
|
" return x"
|
||||||
],
|
]
|
||||||
"execution_count": 25,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"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",
|
"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",
|
"\n",
|
||||||
|
@ -387,80 +397,86 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 26,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"102.49999999999999\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"result = interest(100, 2.5)\n",
|
"result = interest(100, 2.5)\n",
|
||||||
"print(result)"
|
"print(result)"
|
||||||
],
|
|
||||||
"execution_count": 26,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": "102.49999999999999\n",
|
|
||||||
"name": "stdout"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"We can also directly use `interest` in any expression, for example, just to print the amount in one year, we can write"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"interest(100, 2.5)"
|
|
||||||
],
|
|
||||||
"execution_count": 27,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"output_type": "execute_result",
|
|
||||||
"execution_count": 27,
|
|
||||||
"data": {
|
"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",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"And to calculate the resulting amount in two years:"
|
"And to calculate the resulting amount in two years:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 28,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"interest(interest(100, 2.5),2.5)"
|
|
||||||
],
|
|
||||||
"execution_count": 28,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"output_type": "execute_result",
|
|
||||||
"execution_count": 28,
|
|
||||||
"data": {
|
"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",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Local and Global Variables\n",
|
"## Local and Global Variables\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -470,10 +486,20 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 30,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"107.68906249999996\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"interest_rate = 2.5\n",
|
"interest_rate = 2.5\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -481,19 +507,11 @@
|
||||||
" return x * (1+interest_rate/100)\n",
|
" return x * (1+interest_rate/100)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(interest(interest(interest(100))))"
|
"print(interest(interest(interest(100))))"
|
||||||
],
|
|
||||||
"execution_count": 30,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": "107.68906249999996\n",
|
|
||||||
"name": "stdout"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Tuples\n",
|
"## Tuples\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -503,105 +521,121 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 31,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"point = (0,10)"
|
"point = (0,10)"
|
||||||
],
|
]
|
||||||
"execution_count": 31,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"To access individual coordinates of a point, we can use the notation `point[0]` and `point[1]`:"
|
"To access individual coordinates of a point, we can use the notation `point[0]` and `point[1]`:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 32,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"print(\"Our coordinates are: x=\",point[0],', y=',point[1])"
|
|
||||||
],
|
|
||||||
"execution_count": 32,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": "Our coordinates are: x= 0 , y= 10\n",
|
"text": [
|
||||||
"name": "stdout"
|
"Our coordinates are: x= 0 , y= 10\n"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"print(\"Our coordinates are: x=\",point[0],', y=',point[1])"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Another way to decompose a tuple into parts is assigning it to a pair of variables. You can write:"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Our coordinates are: x= 0 , y= 10\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"x,y = point\n",
|
"x,y = point\n",
|
||||||
"print(\"Our coordinates are: x=\",x,', y=',y)"
|
"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",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"By the way, using tuples you can write nice assignments for several variables at once, for example"
|
"By the way, using tuples you can write nice assignments for several variables at once, for example"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 34,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"10"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 34,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"x,y = 0,10\n",
|
"x,y = 0,10\n",
|
||||||
"x+y"
|
"x+y"
|
||||||
],
|
|
||||||
"execution_count": 34,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "execute_result",
|
|
||||||
"execution_count": 34,
|
|
||||||
"data": {
|
|
||||||
"text/plain": "10"
|
|
||||||
},
|
|
||||||
"metadata": {}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Coming back to the interest rate example, we can return total amount and accumulated interest using a tuple:"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"102.5 2.5\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"def interest(x,rate):\n",
|
"def interest(x,rate):\n",
|
||||||
" acc = x*rate/100\n",
|
" acc = x*rate/100\n",
|
||||||
|
@ -609,19 +643,11 @@
|
||||||
"\n",
|
"\n",
|
||||||
"total, acc = interest(100,2.5)\n",
|
"total, acc = interest(100,2.5)\n",
|
||||||
"print(total,acc)"
|
"print(total,acc)"
|
||||||
],
|
|
||||||
"execution_count": 35,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": "102.5 2.5\n",
|
|
||||||
"name": "stdout"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Another Style of Drawing\n",
|
"## Another Style of Drawing\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -637,56 +663,58 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def square(x1,y1,x2,y2):\n",
|
"def square(x1,y1,x2,y2):\n",
|
||||||
" turtle.line((x1,y1),(x1,y2))\n",
|
" turtle.line((x1,y1),(x1,y2))\n",
|
||||||
" turtle.line((x1,y1),(x2,y1))\n",
|
" turtle.line((x1,y1),(x2,y1))\n",
|
||||||
" turtle.line((x2,y2),(x1,y2))\n",
|
" turtle.line((x2,y2),(x1,y2))\n",
|
||||||
" turtle.line((x2,y2),(x2,y1))"
|
" turtle.line((x2,y2),(x2,y1))"
|
||||||
],
|
]
|
||||||
"execution_count": 5,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Using this function, we can draw a house:"
|
"Using this function, we can draw a house:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"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": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"square(0,0,120,120)\n",
|
"square(0,0,120,120)\n",
|
||||||
"square(40,40,80,80)\n",
|
"square(40,40,80,80)\n",
|
||||||
"turtle.line((0,120),(60,150))\n",
|
"turtle.line((0,120),(60,150))\n",
|
||||||
"turtle.line((60,150),(120,120))\n",
|
"turtle.line((60,150),(120,120))\n",
|
||||||
"turtle.done()"
|
"turtle.done()"
|
||||||
],
|
|
||||||
"execution_count": 7,
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"output_type": "display_data",
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD4CAYAAADsBlOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAABMBJREFUeJzt2K2OpFUYRtFzyBCCIUFiEdwEnqsAMQ7PpZCgUQiCwnAtaBwBLAnmoEhmPjrQ01Nd389eS5d4k6pnJ6fmWmsAXe/sfQCwLxGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBGAOBEImXN+Mud8b+87OBYRCJhzfjjn/GGM8fMY448555d738RxiMCFvTL+38YYn44xXo4xvh9jfD3n/F0MGEMELumB8X+x1vporfXtWuvlGOODMcaPQwwYInAp/zH+71793FrrTzHgHyJwAY8d/5YYMIYInNpTx78lBm0icEK3Gv+WGDSJwIk81/i3xKBFBE7gXuPfEoMGETiwvca/JQbXJgIHdJTxb4nBNYnAgRx1/FticC0icABnGf+WGFyDCOzorOPfEoNzE4EdXGX8W2JwTiJwR1cd/5YYnIsI3EFl/FticA4i8Iyq498Sg2MTgWdg/A8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ECcCECcCECcCECcCECcCECcCECcCEPc33Gm/GI8qlCkAAAAASUVORK5CYII=\n",
|
|
||||||
"text/plain": "<Figure size 432x288 with 1 Axes>"
|
|
||||||
},
|
|
||||||
"metadata": {
|
|
||||||
"needs_background": "light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## An Exercise\n",
|
"## An Exercise\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -715,57 +743,62 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 13,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"4.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 13,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import math\n",
|
"import math\n",
|
||||||
"math.sqrt(16)"
|
"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": {
|
"metadata": {
|
||||||
"trusted": true
|
"trusted": true
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Write your solution here"
|
"# Write your solution here"
|
||||||
],
|
]
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
"interpreter": {
|
||||||
|
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
|
||||||
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"name": "python36",
|
|
||||||
"display_name": "Python 3.6",
|
"display_name": "Python 3.6",
|
||||||
"language": "python"
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"name": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.6.6",
|
|
||||||
"file_extension": ".py",
|
|
||||||
"codemirror_mode": {
|
"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": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 2
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ If Python and pip are installed a version number will be displayed, such as *3.8
|
||||||
|
|
||||||
### Visual Studio Code
|
### 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 [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.
|
* 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.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче