Tim Skov Jacobsen 2020-01-21 09:17:37 +01:00
commit d1c15f682a
4 changed files with 23 additions and 24 deletions

View File

@ -1701,7 +1701,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.4" "version": "3.7.5"
}, },
"latex_envs": { "latex_envs": {
"LaTeX_envs_menu_present": true, "LaTeX_envs_menu_present": true,

View File

@ -89,7 +89,7 @@
"source": [ "source": [
"* **Note 1:** Call to function `circle_area` defined in Exercise instead of defining the expression `pi * r**2 / 4` again. The concept of functions calling other functions can be used to make modular programs that are easy to follow and maintain. Each function only needs to do a small thing in itself.\n", "* **Note 1:** Call to function `circle_area` defined in Exercise instead of defining the expression `pi * r**2 / 4` again. The concept of functions calling other functions can be used to make modular programs that are easy to follow and maintain. Each function only needs to do a small thing in itself.\n",
"\n", "\n",
"* **Note 2:** The input parameter when the function was *defined* was a list called `radii`, but the when the function was *called*, the input list was called `list_of_radii`. Thus, the input parameters passed into a function do not need to have the same name as when the function is defined." "* **Note 2:** The input parameter when the function was *defined* was a list called `radii`, but when the function was *called*, the input list was called `list_of_radii`. Thus, the input parameters passed into a function do not need to have the same name as when the function is defined."
] ]
}, },
{ {
@ -823,7 +823,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.4" "version": "3.7.5"
}, },
"latex_envs": { "latex_envs": {
"LaTeX_envs_menu_present": true, "LaTeX_envs_menu_present": true,

View File

@ -49,7 +49,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -68,7 +68,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -77,7 +77,7 @@
"36.25" "36.25"
] ]
}, },
"execution_count": 2, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -95,7 +95,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -127,7 +127,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -162,17 +162,16 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"cell_style": "center"
},
"source": [ "source": [
"## Examples of built-in functions\n",
"### Using `enumerate` for looping in index/value pairs\n", "### Using `enumerate` for looping in index/value pairs\n",
"The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:" "The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -198,7 +197,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -230,7 +229,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -268,7 +267,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -304,7 +303,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -327,14 +326,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"`zip` stops when the shortest iterable is exhausted. So if if `c` is removed from the first string in the example above, we have iterables of lengths 2, 3 and 3. \n", "`zip` stops when the shortest iterable is exhausted. So if `c` is removed from the first string in the example above, we have iterables of lengths 2, 3 and 3. \n",
"\n", "\n",
"Thus, only two iterations are performed:" "Thus, only two iterations are performed:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -407,7 +406,7 @@
" # Your code goes here\n", " # Your code goes here\n",
"~~~\n", "~~~\n",
"\n", "\n",
"Try to call it to see if it works. If you want to access `pi` to avoid typing it out yourself, put the line `from math import pi` at some point before calling the `circle_area` function.\n" "Try to call it to see if it works. If you want to access `pi` to avoid typing it out yourself, put the line `from math import pi` at some point before defining the `circle_area` function.\n"
] ]
}, },
{ {
@ -415,7 +414,7 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Exercise 2\n", "# Exercise 2\n",
"Write a function that takes a list `radii` as input and returns a list of the corresponding circle areas. Try to set it up from scratch and test it.\n", "Write a function that takes a list `radii` as input and returns a list of the corresponding circle areas. Try to set it up from scratch and test it (note that the build-in `map()` function does the same).\n",
"\n", "\n",
"You can use the function from the previous exercise if you want." "You can use the function from the previous exercise if you want."
] ]
@ -574,7 +573,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -847,7 +846,7 @@
"<IPython.core.display.HTML object>" "<IPython.core.display.HTML object>"
] ]
}, },
"execution_count": 11, "execution_count": 12,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -875,7 +874,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.4" "version": "3.7.5"
}, },
"latex_envs": { "latex_envs": {
"LaTeX_envs_menu_present": true, "LaTeX_envs_menu_present": true,

View File

@ -1105,7 +1105,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.4" "version": "3.7.5"
}, },
"latex_envs": { "latex_envs": {
"LaTeX_envs_menu_present": true, "LaTeX_envs_menu_present": true,