簡體   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