Question 4
Back to Exercise
What is the output of the following Python program?
n = 10
steps = 0
while n > 0:
n -= 3
steps += 1
print(n, steps)
- A -2 4 Correct
- B 1 3
- C 0 4
- D -2 3
Correct Answer: Option A
n goes 10 → 7 → 4 → 1 → -2. The condition is checked only before each pass, so n overshoots to -2 after 4 steps.
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!