如何在原始输入中搜索特定单词?

2024-09-30 02:18:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我一直在使用的代码,它只是不断出现错误,我使用的是Python2.7,建议或帮助会非常有用。我在努力

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


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

elif "broken" in problem
    print "sdfghf"

Tags: 代码ininputyourrawifis错误
2条回答

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

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

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

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

elif "broken" in problem:
    print "sdfghf"

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

if语句: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"

相关问题 更多 >

    热门问题