Python 每次运行此代码时,我都会得到回溯(最近一次调用),如何修复此问题?
我在PyCharm 2.7上运行此代码,每次输入一个输入作为名称时,都会出现以下错误:Python 每次运行此代码时,我都会得到回溯(最近一次调用),如何修复此问题?,python,debugging,Python,Debugging,我在PyCharm 2.7上运行此代码,每次输入一个输入作为名称时,都会出现以下错误: Traceback (most recent call last): File "C:/Users/Korisnik/PycharmProjects/untitled/Program test.py", line 4, in <module> character_name = input("Select a name for your character: ") File "<
Traceback (most recent call last):
File "C:/Users/Korisnik/PycharmProjects/untitled/Program test.py", line 4, in <module>
character_name = input("Select a name for your character: ")
File "<string>", line 1, in <module>
NameError: name 'aaa' is not defined
Process finished with exit code 1
如果这是Python2,则需要使用
raw\u input
而不是input
。(或切换到Python 3)如果这是Python 2,则需要使用raw\u input
而不是input
。(或切换到Python 3)将“Or”改为“AND”,并在Python 3中运行
您可以将此网站用于python 3
答复
这是您的代码:将“OR”改为“AND”,并在python 3中运行
您可以将此网站用于python 3
答复
这是您的代码:使用原始输入来代替python2中的输入。
例如:-character\u name=raw\u input(“为您的角色选择一个名称:”)使用raw\u input代替python2中的input。
例如:-character\u name=原始输入(“为您的角色选择一个名称:”)您编写的代码就像Python 3一样,但在Python 2上运行。这是否回答了您的问题?LeopardShark回答了我的问题。您编写的代码就像Python 3一样,但在Python 2上运行。这是否回答了您的问题?豹鲨回答了我的问题,谢谢!这很有效。我会在8分钟内接受你的回答。谢谢!这很有效。我会在8分钟内接受你的回答。
print("-- Story generator by Mateo Primorac --")
character_name = input("Select a name for your character: ")
character_age = input("Select the age for your character: ")
character_gender = input("Select a gender for your character: ")
character_color = input("Select your characters favorite color: ")
if character_gender == "male" or "Male":
print("There was once a man called " + character_name + ",")
print("He is " + character_age + " years old.")
print("He likes wearing " + character_color + " shirts and pants because that is his favorite color.")
print("Press space or enter to exit.")
input()
quit()
if character_gender == "female" or "Female":
print("There was once a woman called " + character_name + ",")
print("She is " + character_age + " years old.")
print("She likes wearing " + character_color + " shirts and dresses because that is her favorite color.")
print("Press space or enter to exit.")
input()
quit()