Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Consider the following Python code. What will be the output if the code is executed?
count = 0
while count >= 10:
    count += 1
    print(count)
Options
A 0
Correct Answer
B 11
C Error
D None of the above
Correct Answer

Option A is the correct answer.

Detailed Explanation

The condition for the while loop is count >= 10. Initially, count is 0. Since 0 is not greater than or equal to 10, the condition count >= 10 is False from the very beginning. Therefore, the loop body will never execute, and nothing will be printed. The variable count remains 0.

Hint

Pay close attention to the initial value of 'count' and the loop condition.

Question Info