我正在建立一个小型汽车模拟器游戏。它就像一个终端窗口,我输入start,它就正常启动了。我按下stop,它就会停止。不幸的是,当我再次启动它时,我遇到了这样的错误。
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论坛,就像那样。代码如下:
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":请谁给我解释一下
发布于 2021-08-22 02:07:17
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":输出
[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
注意:删除了部分代码以对其进行测试。
https://stackoverflow.com/questions/68865900
复制相似问题