好吧,我是新來的編程,並試圖在python中做一個簡單的chatterbot程序。我寫了這個代碼 -如何在Python中使用if函數的raw_input函數?
while (True):
command = raw_input(shayon)
if command == "abarjigay":
print ("Yahoo!")
並且它不工作。問題是什麼?
好吧,我是新來的編程,並試圖在python中做一個簡單的chatterbot程序。我寫了這個代碼 -如何在Python中使用if函數的raw_input函數?
while (True):
command = raw_input(shayon)
if command == "abarjigay":
print ("Yahoo!")
並且它不工作。問題是什麼?
command = raw_input(shayon)
變量shayon
使你的程序有NameError
崩潰不在此行之前定義。
事先指定shayon
,或者如果您希望實際的字母序列「shayon」作爲輸入提示出現在用戶身上,請使用字符串文字。
shayon = "what is your favorite color?"
while (True):
command = raw_input(shayon)
if command == "abarjigay":
print ("Yahoo!")
或
while (True):
command = raw_input("shayon")
if command == "abarjigay":
print ("Yahoo!")
在您建議的更改後,該程序就像一個魅力。非常感謝:) :) :) –
如果你使用的是Python 3應該使用輸入功能。請參閱文檔:https://www.python.org/dev/peps/pep-3111/#specification
我使用python 2.7.6。不管怎麼說,還是要謝謝你 :) –
'什麼是不工作?它會崩潰嗎?命令是否有不同的價值? Python錯誤? – RvdK
您使用'print'作爲函數,但也使用'raw_input'。所以爲了確保我們在同一頁面上,您使用的是什麼版本的Python? – DeepSpace
如果shayon被定義,它應該至少運行 –