Traceback (most recent call last):
File "main.py", line 217, in <module>
prompt()
File "main.py", line 83, in prompt
prompt()
TypeError: 'str'
这是输入以下代码后出现的错误:
def prompt():
print("What would you like to do?")
prompt = input("")
if prompt.upper() == "M":
maps()
prompt()
elif prompt.upper() == "D":
print("You go down.")
spc()
prompt()
elif prompt.upper() == "U":
print("You go up.")
spc()
prompt()
elif prompt.upper() == "L":
print("You go left.")
spc()
prompt()
elif prompt.upper() == "R":
print("You go right.")
spc()
prompt()
else:
print("You cannot do that.")
spc()
prompt()
是的,我知道目前没有办法摆脱循环,但是我正在努力解决这一问题,我不知道这是否是希望的问题。如果有人有解决方案,我将接受大多数代码。尽管我只有大约一年的经验,所以没有什么非常复杂的。谢谢!
答案 0 :(得分:0)
您可以更改函数prompt
的名称或变量prompt
的名称。这样,您的问题就会得到解决。
def prmpt():
print("What would you like to do?")
prompt = input("")
if prompt.upper() == "M":
maps()
prmpt()
elif prompt.upper() == "D":
print("You go down.")
spc()
prmpt()
elif prompt.upper() == "U":
print("You go up.")
spc()
prmpt()
elif prompt.upper() == "L":
print("You go left.")
spc()
prmpt()
elif prompt.upper() == "R":
print("You go right.")
spc()
prmpt()
else:
print("You cannot do that.")
spc()
prmpt()