Back in the day, it was common practice for teachers to issue pupils with ‘lines’ to complete in detention. This involved writing the same thing over and over again. For example ‘I must remember a pencil’.
This program outputs the above sentence 20 times.
You can see the code below, or you can access it on repl.it by clicking here.
Code
![](https://blogs.glowscotland.org.uk/glowblogs/public/insidem11/uploads/sites/10357/2023/05/26133437/image-13.png)
Output
![](https://blogs.glowscotland.org.uk/glowblogs/public/insidem11/uploads/sites/10357/2023/05/26133447/image-14.png)
New Constructs/Concepts
Fixed Loop
This program introduces the concept of a ‘fixed loop’. This is used to repeat a block of code a fixed amount of times. In this case, the block of code is just one line (Line 3) and it is repeated 10 times.
Remember that a block of code must be indented to clearly display which lines of code are part of the block.
Construct | Line(s) | Python Syntax | Purpose |
---|---|---|---|
Fixed Loop | 2 | for index in range(x): | To repeat a block of code a fixed amount of times |