列表中的单词,如果没有错误

时间:2016-10-10 11:56:20

标签: python-3.4

你好%s在这段代码中意味着什么?我以前从未见过它,所以它让我困惑。

sentance = input("Type in your sentance")
lower = sentance.lower()
text = lower.split()
Word = input("What word would you like to find?" ).lower()
position = 1
result = ""
for word in text:
    if (word == Word):
        if result == "":
            result = result + str(position)
        else:
            result = result + "," + str(position)
    position = position+1

if result!= "":
    print("The word %s is in position/s  %s" % (Word,result))
else:
    print('word not found')

需要尽快 谢谢!

1 个答案:

答案 0 :(得分:0)

这对你有用:

sentance = input("Type in your sentance\n")
lower = sentance.lower()
text = lower.split()
findWord = input("What word would you like to find?" ).lower()
position=1
result=""
for word in text:
    if (word == findWord):
        if result=="":
            result=result+str(position)
        else:
            result=result+","+str(position)
    position=position+1

if result!="":
    print("The word %s is in positions. result %s etc.." % (findWord,result))
else:
    print('word not found')