Four runners get three attempts each at sports day. What order do they go in?
You're organising sports day at a school in Leeds. Four runners get three attempts each, and each runner must finish all three before the next runner starts. How could you make a program print the schedule in the right order?
Start with one runner. You've traced loops before: follow the counter from one to two to three. Here you know the exact number of repeats, so you can use a count-controlled loop. Each counter value gives you one attempt.
Watch the runner counter stay at one while the attempt counter goes from one to two to three. Only then does the runner counter move to two. For runner two, the attempt counter starts again at one and goes through two and three.
You're tracing the schedule and you've just written runner two, attempt three. Decide which counter moves on and which one starts again. Pick the next entry.
The named constants RUNNERS and ATTEMPTS stay fixed. Python's range stops before its end value, so add one to each limit. The outer loop counts runners from one to four. Inside it, the attempt counter goes from one to three each time. That's nested iteration. The print call runs once per pair.
To count how often the print line runs, give each runner one group of three. You have four groups, so write three four times and add them. You can write the same count as four times three. That's twelve executions of the print line.
Now you have five runners and two attempts for each runner. The program still prints one line for every attempt. How many times will the print line run? Pick an answer.
If you jump to runner two after the first print, you skip runner one's next two attempts. Keep the runner fixed until their attempts are finished. Adding four and three also misses the groups: you print three lines for each of the four runners.
If you're asked to state the output, write exactly what the program prints, in order. This excerpt starts at line eight: three space two, then three space three. On line ten, the runner changes to four and the attempt starts again at one, so write four space one.