How to make a python program that lists the positions and displays and error message if not found
<p>I did this code:</p>

<pre><code>sentence = input("Type in your sentance ").lower().split()
Word = input("What word would you like to find? ")
Keyword = Word.lower().split().append(Word)
positions = []

for (S, subword) in enumerate(sentence):
    if (subword == Word):
        positions.append
        print("The word" , Word , "is in position" , S+1)
</code></pre>

<p>But there are 2 problems with it; I dont know how to write a code when the users word is not found and to but the positions in "The word position is in [1,3,6,9].
Any help?
Thanks</p>

<blockquote>
  <p>Use index.</p>
</blockquote>

<pre><code>a = 'Some sentence of multiple words'
b = 'a word'


def list_matched_indices(list_of_words, word):
    pos = 0
    indices = []
    while True:
        try:
            pos = list_of_words.index(word, pos)
            indices.append(pos)
            pos+=1
        except:
            break
    if len(indices):
        print(indices)
        return indices
    else:
        print ("Not found")

list_matched_indices(a, b)
</code></pre>

python