minor tweaks and typo fixes

pull/10/head
Kenneth C. Kleissl 2020-01-10 10:24:19 +01:00
parent 171368656f
commit 2e2a4dd7d4
2 changed files with 21 additions and 11 deletions

View File

@ -374,7 +374,7 @@
"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",
"\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."
]
},
{
@ -814,7 +814,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.7.5"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,

View File

@ -292,7 +292,7 @@
},
"source": [
"\n",
"# 3. - Functions\n",
"# 3. Functions\n",
"A **function** is a block of code that is first defined, and thereafter can be called to run as many times as needed. A function might have arguments, some of which can be optional if a default value is specified.\n",
"\n",
"A function is called by parentheses: `function_name()`. Arguments are placed inside the parentehes and comma separated if there are more than one.\n",
@ -447,10 +447,20 @@
},
{
"cell_type": "markdown",
"metadata": {
"cell_style": "center"
},
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-1-febc0acd8c48>, line 3)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-1-febc0acd8c48>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"## Examples of built-in functions\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:"
]
@ -612,7 +622,7 @@
"cell_type": "markdown",
"metadata": {},
"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",
"Thus, only two iterations are performed:"
]
@ -692,7 +702,7 @@
" # Your code goes here\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"
]
},
{
@ -700,7 +710,7 @@
"metadata": {},
"source": [
"# 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",
"You can use the function from the previous exercise if you want."
]
@ -866,7 +876,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.7.5-final"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
@ -907,4 +917,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}