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

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • Does this answer your question? [Python Turtle.Terminator even after using exitonclick()](https://stackoverflow.com/questions/45534458/python-turtle-terminator-even-after-using-exitonclick) – ggorlen Sep 21 '22 at 02:57

1 Answers1

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.

Tharanga Abeyseela
  • 3,255
  • 4
  • 33
  • 45