How To Find The Position Of A Word In A List Made By The User
<p>Code: (Python 3.5.2)</p>

<pre><code>import time
import sys


def Word_Position_Finder():
    Chosen_Sentence = input("Make a simple sentence: ").upper()
    print(Chosen_Sentence)
    Sentence_List = Chosen_Sentence.split()
    if len(Chosen_Sentence) == 0:
        print("Your Sentence has no words! Restarting Program.")
        time.sleep(1)
        Restarting_Program()        
    print(Sentence_List)
    time.sleep(1)
    Users_Choice = input("Do you want to make a new sentence (press 1) or keep current sentence (press 2): ")
    if Users_Choice == "1":
        print("Restarting Program.")
        time.sleep(1)
        Restarting_Program()           
    elif Users_Choice == "2":
        #Lines Under Here Don't Work As Wanted
        print("'" + Chosen_Sentence + "'" + ". This is your sentence.")
        Chosen_Word = input("Which word in your sentence do you want to find the position of? ").upper()
        for Users_List in Sentence_List:
            if  Users_List == Chosen_Word.upper():
                print("Your word appears in the number " + str((Users_List.index(Chosen_Word) +1)) + " slot of this sentence")
        #Lines Above Here Don't Work As Wanted
    else:
        print("That isn't a valid answer")
        Choose_To_Restart()

def Choose_To_Restart():
    time.sleep(1)
    loop = input("Want to try again, Y/N?")
    if loop.upper() == "Y" or loop.upper() == "YES":
        print("Restarting Program")
        time.sleep(1)
        Restarting_Program()
    elif loop.upper() == "N" or loop.upper() == "NO":
        print("Ending Program")
        time.sleep(1)
        sys.exit("Program Ended")  
    else:
        print("Ok.")
        time.sleep(1)
        sys.exit("Program Ended")


def Restarting_Program():
    Word_Position_Finder()


Word_Position_Finder()
</code></pre>

<p><strong>What The Code Is Trying To Achieve</strong></p>

<ul>
<li>The code above takes a string made by the user, turns it into a list, asks the user if they're happy with this string, then asks the user what word in the list they just made they want to know the position of and pastes the position of that chosen word in the users list.</li>
</ul>

<p><strong>The Question</strong></p>

<ul>
<li>In the code I have put two hashtags, "#The code below this line doesn't work" and "#The code above this line doesn't work". Everything else is fine and doesn't need to be changed, with these four lines I want the user to choose a word and I want to loop through the users pre-made list to find the location(s) of their chosen word. However, what the code currently does is when it gets to the four lines, it will ask the user for the word they want to find in their premade list and always print, "print("Your word appears in the number ""1"" slot of this sentence"). The code will always say it has appeared in slot one, or restart itself. Basically, I just want to know if anyone can try to fix this code because I have spent a solid four hours now messing with these four lines trying to get it to work as wanted.</li>
</ul>

<p>In this line</p>

<pre><code>print("Your word appears in the number " + str((Users_List.index(Chosen_Word) +1)) + " slot of this sentence")
</code></pre>

<p>you are trying to get the index of the Chosen_Word in <em>one</em> of the words of the sentence. You want the index in the sentence. Problem is that</p>

<pre><code>print("Your word appears in the number " + str((Sentence_List.index(Chosen_Word) +1)) + " slot of this sentence")
</code></pre>

<p>isn't working either when Chosen_Word appears more than once in the sentence.
So it is better to reformulate the loop with <em>enumerate</em>:</p>

<pre><code>for i, Users_List in enumerate(Sentence_List):
    if  Users_List == Chosen_Word:
        print("Your word appears in the number " + str(i+1) + " slot of this sentence")
</code></pre>

<p>Note, that I also removed one <em>upper</em> call. You already called <em>upper</em> when the word is input.</p>

<p>Also note, that you do not get an output when the word is not in the sentence. You may want to add a special output in this case.</p>

python