Complete the code to prevent an infinite loop by updating the loop variable.
count = 0 while count < 5: print(count) count [1] 1
Using count += 1 increases the count each time, so the loop will eventually stop.
Complete the code to stop the loop when the user types 'exit'.
while True: command = input('Enter command: ') if command [1] 'exit': break
The loop breaks when the command is exactly 'exit', so we check if command == 'exit'.
Fix the error in the loop condition to prevent an infinite loop.
i = 10 while i > 0: print(i) i [1] 1
i causes the loop to never end.i may not reach 0 and cause infinite loops.Since i starts at 10 and the loop runs while i > 0, we must decrease i with i -= 1 to eventually stop the loop.
Fill both blanks to create a loop that prints even numbers from 2 to 10.
num = 2 while num [1] 10: print(num) num [2] 2
The loop runs while num <= 10 and increases num by 2 each time with num += 2 to print even numbers.
Fill all three blanks to create a loop that counts down from 5 to 1 and stops.
counter = [1] while counter [2] 0: print(counter) counter [3] 1
Start counter at 5, loop while counter > 0, and decrease it by 1 each time with counter -= 1.