count = 1
while count <= 3:
print(count)
count = count + 1Line-by-line explanation
- The counter starts at 1.
- The loop continues while count is at most 3.
- The current number is displayed.
- The final line increases count so the loop can eventually stop.
Tiny Practice
Make the loop display 1 and 2, then stop.
Starter template
count = 1
while CHANGE_ME:
print(count)
count = count + 1Line-by-line explanation
- The counter starts at 1.
- It increases after every display.
Hint
- Continue while count is at most 2.
- Use
<=. - Keep the increment.
Show Solution
count = 1
while count <= 2:
print(count)
count = count + 1Line-by-line explanation
- Count begins at 1.
- The condition allows 1 and 2.
- After count becomes 3, the loop stops.