Question 11
Back to Exercise
What is the output of the following Python program?
i = 0
while i < 3:
i += 1
else:
print("done", i)
j = 0
while j < 3:
j += 1
if j == 2:
break
else:
print("done", j)
print("end", j)
- A done 3 done 2 end 2
- B end 2
- C done 3 end 3
- D done 3 end 2 Correct
Correct Answer: Option D
The first loop ends because its condition becomes false, so else runs. The second ends with break, so its else is skipped.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!