2016-11-19 74 views
0

這是我一直在使用的代碼,它只是不斷出現錯誤,我使用Python 2.7和建議或幫助將是非常有益的。我想如何搜索raw_input中的特定單詞?

print "What is your mobile problem?" 
print "----------------------------" 


problem = raw_input 
if "dropped" in problem 
    print "sdghsd" 

elif "broken" in problem 
    print "sdfghf" 
+0

你在'if'和'elif'條件後缺少冒號(':')......這是Python語法的基本部分。另外,它是Python 2.7中的'raw_input()',而不是'raw_input'。否則,你的搜索字符串條目的邏輯是合理的。 – blacksite

回答

0

你的代碼只是罰款不斷產生錯誤的唯一的事情就是你忘記添加在if語句結尾

所以你的代碼應該看起來像這樣

print "What is your mobile problem?" 
print "----------------------------" 

problem = raw_input() 
if "dropped" in problem: 
    print "sdghsd" 

elif "broken" in problem: 
    print "sdfghf" 
相關問題