Ask coding questions

← Back to all posts
Accidentally created an infinite loop cant find it
OwenCastaneda (0)

A program that acts as a tv/remote. Has the ability to change channel, volume, turn power on and off (off ends the program). Also the tv starts in the off state so you have to turn it on in the beginning

Answered by Bergreen (10) [earned 5 cycles]
View Answer
Bergreen (10)

The problem is with this section of the code:

while choice != "0":
    print \
    Critter Caretaker
    0 - Turn Off TV
    1 - Turn On TV
    2 - Channel Up
    3 - Channel Down
    4 - Turn Volume Up
    5 - Turn Volume Down
    6 - Info

choice = input("Choice: ")

The program infinitely prints then menu while choice does not equal 0, but you are not updating choice within the while loop, so it ends up printing infinitely. Simply indent this line so it is in the while loop: choice = input("Choice: "). This will allow the variable to be changed each time the menu is printed.