lundi 9 décembre 2019

How to check if a command has already been executed

Here's the problem : I don't know how to write the script so that if I type more than once start or stop the script will print something like "Already running" or "Not running"

running = True
print("Type help for a list of commands. ")
while running :
    user=input("> ")
    user_input=user.upper()
    if user_input==("HELP"):
        print(f"""Type start to start the car.
Type stop to stop the car.
Type quit to quit the game.""")
    elif user_input==("START"):
        print("You started the car. ")
    elif user_input==("STOP"):
        print("You stopped the car. ")
    elif user_input==("QUIT"):
        print("You stopped the game.")
        running=False
    elif user_input!=("START") and user_input!=("STOP") and user_input!=("QUIT"):
        print("I don't understand that. ")

Example:

 >start
You started the car.
 >start
Car is already running.
 >stop
You stopped the car.
 >stop
Car isn't turned on.

Aucun commentaire:

Enregistrer un commentaire