hangman: UnboundLocalError: local variable referenced before assignment
<p>I made a program to play hangman. I got pretty far but no matter how many times i try to fix it or make a different variation, the shell just comes up with the same thing.</p>

<p><code>UnboundLocalError: local variable '' referenced before assignment.
</code></p>

<p>I'm fairly new so can you make the answers as simple as possible. (or just a de-bugged version). </p>

<pre><code>import random
tries = 12
def intro ():
    print ('the size of your word is '+str(size))
    print ('you have ' + str(tries) + ' tries')
# word == car     output == '***'  
print (output)
def guesses ():
    guess = ('it')
    while len(guess) &gt; 1:
        guess = str(input('pick a letter ')) 

if guess not in word:
    print ('incorrect')
    tries = tries - 1
    print ('you have ' + str(tries) + ' tries')

if guess in word:
    print ('correct!!')
    tries = tries - 1
    position = word.index(guess)
    output = output[:position] + guess + output[position+1:]
    print ('you have ' + str(tries) + ' tries')

print ('this is a game of hangman where you get a word')
print ('that you have to guess letter by letter')
print ('')
print ('')
word_list = ['jazz', 'whale', 'surgery', 'love']
word = random.choice(word_list)
size = len(word)
output = '*' * size
intro ()    

while output != word or tries != 0:
    guesses ()
    print (output)
</code></pre>

<p>I think you are missing a <strong>global</strong> statement such as</p>

<pre><code>def guesses ():
    global tries
    #... some of your code...
    #and now this line will work! :)
    tries = tries - 1
</code></pre>

<p>this kind of error usually comes up when you see code like this:</p>

<pre><code>def f():
    x = x + 1
</code></pre>

<p>without a <strong>global</strong> statement </p>

<p>That said - try not to use <strong>global</strong> at all but to pass parameters to the function such as :</p>

<pre><code>def guesses (tries):
    #now tries is a local variable and the next line works
    tries = tries - 1
</code></pre>

python debugging