我完全失去了爲什麼這不起作用。應該準確地工作,對嗎?「用戶在Python中輸入後NameError:name''未定義'
UserName = input("Please enter your name: ")
print ("Hello Mr. " + UserName)
raw_input("<Press Enter to quit.>")
我得到這個異常:
Traceback (most recent call last):
File "Test1.py", line 1, in <module>
UserName = input("Please enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'k' is not defined
它說NameError 'k'
,因爲我寫'k'
因爲在我的測試輸入。我讀過的印刷語句過去沒有括號,但已被棄用的權利?
'輸入'相當於'eval(raw_input(提示))'。你只需要'raw_input()'。 – 2010-01-19 02:42:15
input()與Python 3k一致。 @OP你使用的是什麼版本的Python? – ghostdog74 2010-01-19 02:50:41
@Sergio這與您的問題無關,但您應該使用小寫第一個字母作爲變量名(例如'userName'而不是'UserName')。 – Roman 2010-01-19 03:00:25