This is an enhanced version of the Detention Lines program. This time you can enter a sentence of your own and an amount of lines.
You can see the code and output 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/26134414/image-15.png)
Output
![](https://blogs.glowscotland.org.uk/glowblogs/public/insidem11/uploads/sites/10357/2023/05/26134441/image-16.png)
New Constructs/Concepts
This program doesn’t reveal any new constructs, however it shows some of the more advanced features of the Fixed Loop (for statement).
Variable as a limit
In this version of the program, instead of a given number, we use the contents of a variable (lines). A fixed loop can take a literal number or a integer variable as its limit (the amount of times it will repeat).
The ‘index’ variable
As you can see on line 9, inside our fixed loop, we concatenate a variable called ‘index’ with the sentence entered by the user.
The ‘index’ variable keeps track of how many times the loop has been round, starting at 0. So on the first iteration, index is 0, on the second, index is 1, etc.
Programmers can choose to call the index variable whatever they like, counter and index are the most common choices. Examples:
- for index in range(10)
- for counter in range(10)
- for iteration in range(10)
- for x in range(1)
- for i in range(10)
Parsons Problem
Hint: Remember that in order to use a time delay, the first line of the program needs to import the time package.