|
49 | 49 | "When you call one of these functions, it returns a value you can assign to a variable or use as part of an expression.\n", |
50 | 50 | "\n", |
51 | 51 | "The functions we have written so far are different.\n", |
52 | | - "Some use the `print` function to display values, and some use `Turtle` functions to draw figures.\n", |
| 52 | + "Some use the `print` function to display values, and some use turtle functions to draw figures.\n", |
53 | 53 | "But they don't return values we assign to variables or use in expressions.\n", |
54 | 54 | "\n", |
55 | 55 | "In this chapter, we'll see how to write functions that return values." |
|
1162 | 1162 | "n! &= n~(n-1)!\n", |
1163 | 1163 | "\\end{aligned}$$ \n", |
1164 | 1164 | "\n", |
1165 | | - "This definition says that the factorial of 0 is 1, and the factorial of any other value, $n$, is $n$ multiplied by the factorial of $n-1$.\n", |
| 1165 | + "This definition says that the factorial of $0$ is $1$, and the factorial of any other value, $n$, is $n$ multiplied by the factorial of $n-1$.\n", |
1166 | 1166 | "\n", |
1167 | 1167 | "If you can write a recursive definition of something, you can write a Python program to evaluate it. \n", |
1168 | 1168 | "Following an incremental development process, we'll start with a function that take `n` as a parameter and always returns `0`." |
|
1184 | 1184 | "id": "ee1f63b8", |
1185 | 1185 | "metadata": {}, |
1186 | 1186 | "source": [ |
1187 | | - "Now let's add the first part of the definition -- if the argument happens to be 0, all we have to do is return 1:" |
| 1187 | + "Now let's add the first part of the definition -- if the argument happens to be `0`, all we have to do is return `1`:" |
1188 | 1188 | ] |
1189 | 1189 | }, |
1190 | 1190 | { |
|
1207 | 1207 | "metadata": {}, |
1208 | 1208 | "source": [ |
1209 | 1209 | "Now let's fill in the second part -- if `n` is not `0`, we have to make a recursive\n", |
1210 | | - "call to find the factorial of $n-1$ and then multiply the result by $n$:" |
| 1210 | + "call to find the factorial of `n-1` and then multiply the result by `n`:" |
1211 | 1211 | ] |
1212 | 1212 | }, |
1213 | 1213 | { |
|
1401 | 1401 | "metadata": {}, |
1402 | 1402 | "source": [ |
1403 | 1403 | "If you try to follow the flow of execution here, even for small values of $n$, your head explodes.\n", |
1404 | | - "But according to the leap of faith, if you assume that the two recursive calls work correctly, you can be confident that the last return statement is correct.\n", |
| 1404 | + "But according to the leap of faith, if you assume that the two recursive calls work correctly, you can be confident that the last `return` statement is correct.\n", |
1405 | 1405 | "\n", |
1406 | 1406 | "As an aside, this way of computing Fibonacci numbers is very inefficient.\n", |
1407 | 1407 | "In [Chapter 10](section_memos) I'll explain why and suggest a way to improve it." |
|
1652 | 1652 | "metadata": {}, |
1653 | 1653 | "source": [ |
1654 | 1654 | "`space` is a string of space characters that controls the indentation of\n", |
1655 | | - "the output. Here is the result of `factorial(4)` :" |
| 1655 | + "the output. Here is the result of `factorial(3)` :" |
1656 | 1656 | ] |
1657 | 1657 | }, |
1658 | 1658 | { |
|
2332 | 2332 | "name": "python", |
2333 | 2333 | "nbconvert_exporter": "python", |
2334 | 2334 | "pygments_lexer": "ipython3", |
2335 | | - "version": "3.10.14" |
| 2335 | + "version": "3.10.11" |
2336 | 2336 | } |
2337 | 2337 | }, |
2338 | 2338 | "nbformat": 4, |
|
0 commit comments