Refurbish chapter 02

- streamline text
- streamline example functions
- move section on built-ins to beginning
- add notes on the concept of a callable
This commit is contained in:
Alexander Hess 2020-02-05 18:31:52 +01:00
commit 3754297c93
4 changed files with 1639 additions and 715 deletions

View file

@ -32,7 +32,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.1**: The [volume of a sphere](https://en.wikipedia.org/wiki/Sphere) is defined as $\\frac{4}{3} * \\pi * r^3$. Calculate this value for $r=10.0$ and round it to 10 digits after the comma. Use the [standard library](https://docs.python.org/3/library/index.html) to obtain a good approximation of $\\pi$."
"**Q1**: The [volume of a sphere](https://en.wikipedia.org/wiki/Sphere) is defined as $\\frac{4}{3} * \\pi * r^3$. Calculate this value for $r=10.0$ and round it to 10 digits after the comma. Use the [standard library](https://docs.python.org/3/library/index.html) to obtain a good approximation of $\\pi$."
]
},
{
@ -66,7 +66,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.2**: Encapsulate the logic into a function `sphere_volume()` that takes one *positional* argument `radius` and one *keyword-only* argument `digits` defaulting to `5`. The volume should be returned as a `float` object under *all* circumstances. Document your work appropriately in a docstring according to [Google's Python Style Guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md)."
"**Q2**: Encapsulate the logic into a function `sphere_volume()` that takes one *positional* argument `radius` and one *keyword-only* argument `digits` defaulting to `5`. The volume should be returned as a `float` object under *all* circumstances. Document your work appropriately in a docstring according to [Google's Python Style Guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md)."
]
},
{
@ -83,7 +83,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.3**: Evaluate the function with `radius = 100.0` and 1, 5, 10, 15, and 20 digits respectively."
"**Q3**: Evaluate the function with `radius = 100.0` and 1, 5, 10, 15, and 20 digits respectively."
]
},
{
@ -144,7 +144,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.4**: What observation do you make?"
"**Q4**: What observation do you make?"
]
},
{
@ -158,7 +158,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.5**: Using the [range()](https://docs.python.org/3/library/functions.html#func-range) built-in, write a `for`-loop and calculate the volume of a sphere with `radius = 42.0` for all `digits` from `1` through `20`. Print out each volume on a separate line.\n",
"**Q5**: Using the [range()](https://docs.python.org/3/library/functions.html#func-range) built-in, write a `for`-loop and calculate the volume of a sphere with `radius = 42.0` for all `digits` from `1` through `20`. Print out each volume on a separate line.\n",
"\n",
"Note: This is the first task where you need to use the built-in [print()](https://docs.python.org/3/library/functions.html#print) function."
]
@ -186,7 +186,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1.6**: What lesson do you learn about the `float` type?"
"**Q6**: What lesson do you learn about the `float` type?"
]
},
{