Program 5: Detention Lines

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

Output

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.

ConstructLine(s)Python SyntaxPurpose
Fixed Loop2for index in range(x):To repeat a block of code a fixed amount of times
Report a Glow concern
Cookie policy  Privacy policy

Glow Blogs uses cookies to enhance your experience on our service. By using this service or closing this message you consent to our use of those cookies. Please read our Cookie Policy.