samedi 9 octobre 2021

How can i fix this "Else" issue on python?

status = 0
while True:
    cmd = input("> ").lower()
    if cmd == "help":
            print('''start - to start the car
        stop - to stop the car
        quit - to exit''')
    elif status  == 0:
        if cmd == "start":
            print("Car started")
            status += 1
        elif cmd == "stop":
            print("car hasn't started yet")
    elif status == 1:
        if cmd == "start":
            print("car already started")
        elif cmd == "stop":
            print('Car stopped')
            status -= 1
    elif cmd == "quit":
        break
    else:
        print("sorry, i don't understand that.")

If you type "help" in the terminal twice, the second one displays the else string, not the string that i set for "help"

someone can help me with this?

Aucun commentaire:

Enregistrer un commentaire