2015-12-03 22 views
-3

好吧,我是新來的編程,並試圖在python中做一個簡單的chatterbot程序。我寫了這個代碼 -如何在Python中使用if函數的raw_input函數?

while (True): 
    command = raw_input(shayon) 
    if command == "abarjigay": 
     print ("Yahoo!") 

並且它不工作。問題是什麼?

+4

'什麼是不工作?它會崩潰嗎?命令是否有不同的價值? Python錯誤? – RvdK

+2

您使用'print'作爲函數,但也使用'raw_input'。所以爲了確保我們在同一頁面上,您使用的是什麼版本的Python? – DeepSpace

+0

如果shayon被定義,它應該至少運行 –

回答

-1
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!") 
+0

在您建議的更改後,該程序就像一個魅力。非常感謝:) :) :) –