繁体   English   中英

每次运行此代码时,我都会得到 Traceback(最近一次调用),如何解决这个问题?

[英]I get Traceback (most recent call last) each time I run this code, how to fix this?

我在 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 "<string>", line 1, in <module>
NameError: name 'aaa' is not defined

Process finished with exit code 1

有没有什么办法解决这一问题? 我是 python 脚本的初学者,所以关于如何解决这个问题的解释会很棒。

这是我的代码:


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()

如果这是 Python 2,则需要使用raw_input而不是input (或切换到Python 3)

将“OR”更改为“AND”并在 python 3 中运行

您可以将此网站用于 python 3

复制

这是您的代码: https://repl.it/repls/DarkvioletRealLocatorprogram#main.py

使用raw_input代替python2中的输入 例如:- character_name = raw_input("为你的角色选择一个名字:")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM