Lesson 3.2
range gives numbers in order:
| Call | Numbers |
|---|---|
range(5) |
0, 1, 2, 3, 4 |
range(1, 6) |
1, 2, 3, 4, 5 |
range(2, 11, 2) |
2, 4, 6, 8, 10 |
The right number is not included. That's why 1 to 5 is range(1, 6): five is not
included, so you have to name it explicitly. The third argument is the step.
On its own range prints nothing: you loop over it in a for.
Multiply the numbers from start to stop inclusive by factor and print each
product on a new line. start, stop and factor are set by the check.
range(start, stop) does not include stop — the upper bound needs a nudge.
range takes two arguments separated by a comma. The loop body, indented 4
spaces, prints the number times factor. Multiplication is *.