title: Python 3.x : UnboundLocalError and Loop
body: <pre><code>words = []
  words_needed = 0
  
  
  def input_words():
      inputWords = input('Please input more words that you want to play with.').lower()
      words.append(inputWords)
      words_needed += 1
      while words_needed &lt; 5:
          input_words()
      else:
          words_needed &gt;= 5
          input_SS = input('Do you want to continue adding words?')
          if input_SS == 'yes':
              input_words()
          elif input_SS == 'no':
              end
  
  def Start_up():
      start_question = input('Do you want to add your own words to the list?')
      if start_question == 'yes':
          input_words()
      elif start_question == 'no':
          pre_words = (*words in a list*)
          words.extend(pre_words)
  
  
  Start_up()
  </code></pre>
  
  <p>When I run this segment of code it either runs off forever of brings me back an error of;</p>
  
  <pre><code>Traceback (most recent call last):
    File "F:\A453\Code\Python Hangman\Hangman.py", line X, in &lt;module&gt;
      Start_up()
    File "F:\A453\Code\Python Hangman\Hangman.py", line Y, in Start_up
      input_words()
    File "F:\A453\Code\Python Hangman\Hangman.py", line Z, in input_words
      words_needed += 1
  UnboundLocalError: local variable 'words_needed' referenced before assignment
  </code></pre>
  
  <p>Im fairly new to coding so any help would be appreciated</p>