I am creating a car game. There are only "start", "stop", "quit" commands. Any other command is not recognized.
command = ""
while command != "quit":
command = input("Command: ")
if command == "start":
print("Car ready to go")
elif command == "stop":
print("Car stopped")
else:
print("I don't understand that")
else:
print("Game exited")
All commands work fine except "quit". With the while loop, it causes both the else statements to be executed and prints:
I don't understand that
Game exited
The command = "quit" should render the while condition False
and thus skip ahead to execute only the outer else statement. Why is it executing both else statements even thought the while condition is not met?