Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Consider the following Python code snippet:
count = 0
while count >= 10:
count += 1
print(count)
What will be the output of this code?
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 while loop condition count >= 10 is evaluated with count initially set to 0. Since 0 >= 10 is False, the loop body (count += 1) is never executed. The program then proceeds to print(count), which outputs the initial value of count, which is 0.

Hint

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

Question Info