Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Why does this program never stop? Fix it so that it shows .
x = 0
while x < 5:
print(x)Something inside a while loop must change the condition.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Why. The value of x never changes. It stays 0, so x < 5 is always true. The loop shows 0 for ever.
Fix. Add a line inside the loop that changes x: x = x + 1. After five rounds, x is 5 and the condition is false.
The code below shows the fixed program.
Log in to join the discussion.
Loading…