このコードを作成して、人に文章を入力するように指示しました。 その後、その文章に単語を入力します。 その後、コードが出力単語がである位置。リスト内で同じ2つの単語の位置を見つける
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))
は私が午前問題は、彼らが文の中で同じ単語のうちの2つを置けば、それは最初のものだけを出力していることであるだろう。どうぞお助けください。
うまく動作します。ありがとうございました。 – Jake