Natalia
Natalia

Reputation: 11

How to fix a while loop that goes on forever in Python?

I am trying to create a simple while loop that will run the commands start, stop, quit, and help. Start, stop, and help will just display some printed text. After they are run, I want it to keep going on to another command. However, on quit I want the whole program to stop.

input_command = input("> ").lower()

while input_command != "quit":
    print(input_command)
    if input_command == "start":
        print("The car is ready! VROOM VROOM!")
        print(input_command)
    elif input_command == "stop":
        print("Car stopped.")
    elif input_command == "help":
        print("""
        start - starts the car
        stop - stops the car
        quit - exits the program
        """)
else:
    print("Sorry, I don't understand that...")

Upvotes: 0

Views: 293

Answers (1)

Sayse
Sayse

Reputation: 43330

You never reassign input command so it only ever takes input once,

input_command = ''

while input_command != "quit":
     input_command = input("> ").lower()

Upvotes: 3

Related Questions