PCEP Control Flow, Loops, Lists and Logic Practice Question
A programmer writes code that uses a while loop to process user input until the user types 'exit'. The code currently prints 'Done' after the loop, but it never exits. What is the most likely cause?
⚠ Common exam trap
Python Institute often tests the distinction between reading input once versus repeatedly inside a loop, and the trap here is that candidates may think 'while True' is always the cause of an infinite loop, overlooking the fact that a loop variable not being updated is the more precise and common reason.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The variable controlling the loop is not updated inside the loop
If the variable controlling the loop (e.g., the user's input) is never updated inside the while loop, the loop condition will never become false, causing an infinite loop. In this scenario, the programmer likely reads input once before the loop but does not call input() again inside the loop to update the variable, so the loop never sees the 'exit' value.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The loop condition is 'while True'
Why it's wrong here
A 'while True' condition with no break statement inside the loop body creates an infinite loop, so the exit input never terminates iteration. It is tempting because 'while True' is a legitimate pattern when a break handles termination; here that break is absent.
- ✗
The print statement is indented incorrectly
Why it's wrong here
Misindenting the print statement changes only whether 'Done' runs inside or after the loop; it cannot prevent the loop from terminating. It is tempting because indentation errors are common Python pitfalls, but they affect output placement or syntax, not loop exit conditions.
- ✗
The input function is called outside the loop
Why it's wrong here
Calling input outside the loop means the value is read once, so the condition never re-evaluates against fresh user input, potentially looping forever. It is tempting because input placement matters, yet the question describes a loop that never exits despite processing input.
- ✓
The variable controlling the loop is not updated inside the loop
Why this is correct
The loop condition depends on a variable that must change each iteration to eventually become false. If that variable is never reassigned inside the loop body, the condition stays true forever, so the loop never terminates and 'Done' is never reached.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.