September 2013
Intermediate to advanced
350 pages
9h 38m
English
Some computations are complex, and breaking them down into separate steps can lead to clearer code. Here, 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):
| | >>> def quadratic(a, b, c, x): |
| | ... first = a * x ** 2 |
| | ... second = b * x |
| | ... third = c |
| | ... return first + second + third |
| | ... |
| | >>> quadratic(2, 3, 4, 0.5) |
| | 6.0 |
| | >>> quadratic(2, 3, 4, 1.5) |
| | 13.0 |
Variables like first, second ...
Read now
Unlock full access