PCEP-30-02 · Question #336
Which one of the lines should you put in the snippet below to match the expected output? Expected output: 1245 Code: c = 0 while c < 5: c = c + 1 if c == 3: # enter code here print(c, end="")
The correct answer is B. continue. Option B (continue) is correct because it tells Python to skip the rest of the current loop iteration and jump back to the while condition check - so when c == 3, the print(c) line is never reached, and the loop continues with c = 4 and c = 5, producing 1245. Why the…
Question
enter code here
print(c, end="")Options
- Aexit
- Bcontinue
- Cprint()
- Dbreak
How the community answered
(32 responses)- A9% (3)
- B84% (27)
- C3% (1)
- D3% (1)
Explanation
Option B (continue) is correct because it tells Python to skip the rest of the current loop iteration and jump back to the while condition check - so when c == 3, the print(c) line is never reached, and the loop continues with c = 4 and c = 5, producing 1245.
Why the distractors fail:
- A (
exit) terminates the entire program immediately, so the output would be just12before the program stops. - C (
print()) doesn't skip anything - it would print an extra blank line and then still executeprint(c), adding3to the output. - D (
break) exits thewhileloop entirely whenc == 3, cutting the output short to just12.
Memory tip: Think of continue as "skip this one and continue on" - it skips forward to the next iteration. Think of break as "break out" - it smashes through the loop wall and exits completely. When you see a question asking to skip a value while the loop keeps going, continue is almost always the answer.
Community Discussion
No community discussion yet for this question.