6/30
Part 2 of 7 · One loop at a timeLearn and do

A loop shows each title once, then starts again

Level 1 is a round robin: walk the sorted titles from the top, and when you pass the end, start again at the top. All it needs is a position, called a cursor, that moves one step per call and wraps around with %:

order = ["Comet", "Harbor", "Maple"]
cursor = 0
shown = []
for _ in range(5):
    shown.append(order[cursor])
    cursor = (cursor + 1) % len(order)
print(shown)
['Comet', 'Harbor', 'Maple', 'Comet', 'Harbor']

(cursor + 1) % len(order) counts 0, 1, 2, 0, 1. The % gives the remainder after dividing, so the step after the last index lands back on 0.

Read before you move. If the cursor moves first, the first call shows the second title, and the best title waits a whole loop.

An empty catalog breaks the modulo: % 0 raises ZeroDivisionError. The prompt says an empty billboard returns None, so check for it before you divide.

The editor holds rotation with its cursor set up. Write rotation(order, n) so it returns the first n titles shown, going round order again and again.