December 2017
Beginner
412 pages
10h 8m
English
Some computations are complex, and breaking them down into separate steps can lead to clearer code. In the next example, we break down the evaluation of the quadratic polynomial ax2+ bx + c into several steps. Notice that all the statements inside the function are indented the same amount of spaces in order to be aligned with each other. You may want to type this example into an editor first (without the leading >>> and ...) and then paste it to the Python shell. That makes fixing mistakes much easier:
| | >>> def quadratic(a, b, c, x): |
| | ... first = a * x ** 2 |
| | ... second = b * x |
| | ... third = c |
| | ... return ... |
Read now
Unlock full access