Fixed Loops

Fixed loops will repeat for a set number of times.

A variable is used to count through the loop, starting from zero

  • give this variable a sensible name
  • if printing the number out, you might want to add 1 to it
#
for pupil in range(5):
 
    name = input('Enter name of pupil:')
    print(f'Pupil {name+1} is {name}')
#

The value for range can be a number, or a variable:

#
classSize = int(input('Enter number of pupils:'))
 
for pupil in range(classSize):
    name = input('Enter name of pupil:')
    print(f'Pupil {name+1} is {name}')
#