1

I am building a small car simulator game. it's like a terminal window, I type start and it started normally. I press stop and it stops. Unfortunately, when I start it again, I had a error like this.

Traceback (most recent call last):

  File "C:\Users\****\OneDrive\New folder\Car Emulator.py", line 12, in <module>
    turtle.shape('square')
  File "<string>", line 5, in shape
turtle.Terminator

I don't know what does this mean, because I called the turtle.bye() function. Although I Searched all the Stack Overflow forums just like that. the code is like this:

while True:
command = input(">").lower()
if command == "start":
    if engine == False:
        engine = True
        print("Car started.")
        t.shape('square')
    else:
        restart = input("Car already started. Restart? (Y) Yes (N) No ")
        if restart.upper == "Y":
            engine = False
            t.bye()
            engine = True
            t.shape('turtle')
            print("Car Restarted.")
elif command == "stop":
    if engine == True:
        engine = False
        t.bye()
        print("Car stopped.")
    else:
        print("Car already stopped.")
elif command == "help":
    print('''
    start - start the car
    stop - stop the car
    quit - exit
    ''')
elif command == "quit":
   

please someone explain this to me

1

1 Answer 1

0
while True:
    command = input(">").lower()
    if command == "start":
        if engine == False:
            engine = True
            print("Car started.")
            #t.shape('square')
        else:
            restart = input("Car already started. Restart? (Y) Yes (N) No ")
            if restart.upper == "Y":
                engine = False
               # t.bye()
                engine = True
                #t.shape('turtle')
                print("Car Restarted.")
    elif command == "stop":
        if engine == True:
            engine = False
            #t.bye()
            print("Car stopped.")
        else:
            print("Car already stopped.")
    elif command == "help":
        print('''
        start - start the car
        stop - stop the car
        quit - exit
        ''')
    elif command == "quit":

output

[root@localhost ~]# python3 test.py
>start
Car started.
>stop
Car stopped.
>start
Car started.
>stop
Car stopped.
>stop
Car already stopped.
>start
Car started.
>start
Car already started. Restart? (Y) Yes (N)

Check your while loop, if you want to repeat anything inside the while loop, it should have a correct indentation. Example https://www.w3schools.com/python/python_while_loops.asp

Note: Removed some part of the code to test it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.