所以作业上说:
除了报告包含单词owl的单词数量外,还应该报告单词出现的索引! 下面是您的程序运行的一个示例:
Enter some text: Owls are so cool! I think snowy owls might be my faborite. Or maybe spotted owls.
There were 3 words that contained "owl".
They occurred at indices: [0, 7, 15]
到目前为止,我的代码是这样的:
sentence = input("Talk about something: ")
sentence.lower()
print "There are " + str(sentence.count("owls)) + " of the word \"owls\" in the sentence"
print "They occurred at indices: " + str(sentence.findl("owls")
但是它只打印它在的第一个索引,如何让它打印它在的所有索引
这很有效
相关问题 更多 >
编程相关推荐