首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复Python Turtle Terminator错误?

如何修复Python Turtle Terminator错误?
EN

Stack Overflow用户
提问于 2021-08-20 17:15:47
回答 1查看 57关注 0票数 0

我正在建立一个小型汽车模拟器游戏。它就像一个终端窗口,我输入start,它就正常启动了。我按下stop,它就会停止。不幸的是,当我再次启动它时,我遇到了这样的错误。

代码语言:javascript
复制
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

我不知道这是什么意思,因为我调用了turtle.bye()函数。尽管我搜索了所有的Stack Overflow论坛,就像那样。代码如下:

代码语言:javascript
复制
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":

请谁给我解释一下

EN

回答 1

Stack Overflow用户

发布于 2021-08-22 02:07:17

代码语言:javascript
复制
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":

输出

代码语言:javascript
复制
[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)

检查你的while循环,如果你想在while循环中重复任何东西,它应该有一个正确的缩进。示例https://www.w3schools.com/python/python_while_loops.asp

注意:删除了部分代码以对其进行测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68865900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档