Predict the output
Round robin over three servers for 9 requests. What's printed?
from itertools import cycle
servers = cycle(["A", "B", "C"])
sent = {"A": 0, "B": 0, "C": 0}
for _ in range(9):
sent[next(servers)] += 1
print(sent)Hint 1 of 1
What does cycle do?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A {'A': 3, 'B': 3, 'C': 3}
Correct. Round robin ignores load: even a slow server gets a third.
itertools.cycle gives A, B, C, A, B, C forever, so 9 requests split 3 each. Round robin counts requests, not load, so a slow server still gets its full share.
Why not the others?
- B
{'A': 9, 'B': 0, 'C': 0}. cycle moves to the next server each time. - C
{'A': 4, 'B': 3, 'C': 2}. 9 divides evenly by 3. - D A random split. Round robin is deterministic.