所以我创建了这个代码来要求一个人输入一个句子。然后他们在那句话中输入一个单词。 然后代码将输出字中的位置。找到列表中相同的两个单词的位置
print("Type a sentence here")
sentence = input("")
sentence = sentence.split()
print("Now type a word in that sentence.")
word = input('')
if word in sentence:
print("I found",word,"in your sentence.")
else:
print("That word is not in your sentence.")
print(sentence.index(word))
我遇到的问题是,如果他们在句子中把同一个词两个它只输出的第一个。请你帮忙。
行之有效。谢谢。 – Jake