所以我創建了這個代碼來要求一個人輸入一個句子。然後他們在那句話中輸入一個單詞。 然後代碼將輸出字中的位置。找到列表中相同的兩個單詞的位置
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