Name "userInput" cannot be defined
<p>i'm practicing some Python and i'm having some trouble trying to compare userInput would selected word in a hangman game. </p>

<pre><code># User guess input (single char)
# Exception handling to limit input to letters between a-z
while True:
    userInput = str(input('Please guess a letter:'))
    if len(userInput) == 1:
        if not re.match("^[a-z]*$", userInput):
            print("Error! Only letters a-z allowed!")
            continue
        break
    else:
        print("Error! Please input a single letter!")
        continue
# Comparing array with input
for i in range(len(selWord)):
    if(userInput == selWord[i]):
</code></pre>

<p>The problem lies in the in the last line:</p>

<pre><code>        if(userInput == selWord[i]):
</code></pre>

<p>It states that  "The name 'userInput' is not defined." however when I try to print outside the initial while loop, it works fine. </p>

<blockquote>
  <p>set userInput = None above while loop</p>
</blockquote>

<p>This was the solution, thank you everyone!</p>

python python-3.x