如何在raw_input中搜索特定单词?

时间:2016-11-19 19:31:26

标签: python

这是我一直在使用的代码,它只是不断出现错误,我使用python 2.7,建议或帮助会非常有帮助。我正在尝试

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


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

elif "broken" in problem
    print "sdfghf"

2 个答案:

答案 0 :(得分:0)

对于Python 2,文档:https://docs.python.org/2/library/functions.html#raw_input

if statement:https://docs.python.org/2/tutorial/controlflow.html

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


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

elif "broken" in problem:
    print "sdfghf"

答案 1 :(得分:0)

您的代码很好,唯一不断产生错误的是您忘记在if语句末尾添加

所以你的代码应该是这样的

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

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

elif "broken" in problem:
    print "sdfghf"