I'm writing the follow python script as a way to implement a slot machine type game using random numbers
<pre><code>from getch import getch, pause
from random import randint



def wheel_spin():


    tokens = 100
    while tokens &gt; 0:

        num_input= getch()

        if num_input == ' ':
            print "You Hit Space Bar"
            draw1 = randint(1,6)
        draw2 = randint(1,6)
        draw3 = randint(1,6)
            print draw1 , draw2 ,draw3

        winning(draw1,draw2,draw3)
        tokens -= 1         

        #pause()


def winning(draw1,draw2,draw3):

if draw1 == draw2 or draw2 == draw3:
    print "YOU WIN"

    tokens += 10

 else:
    pass




wheel_spin()
</code></pre>

<p>The code works fine and generates random numbers but when it comes to the "winning" function where it is supposed to reward the player for getting two of the same numbers it doesn't work I get the following error </p>

<blockquote>
  <p>YOU WIN Traceback (most recent call last):   File "Exercise 36
  Designing and Debugging.py", line 59, in 
      wheel_spin()   File "Exercise 36 Designing and Debugging.py", line 31, in wheel_spin
      winning(draw1,draw2,draw3)   File "Exercise 36 Designing and Debugging.py", line 51, in winning
      tokens += 10 UnboundLocalError: local variable 'tokens' referenced before assignment</p>
</blockquote>

<p>Any help will be greatly appreciated </p>

<p><code>tokens</code> is undefined in the <code>winning</code> method. It's declared in the <code>spin_wheel</code> and is scope-limited to only that method. You either want to pass it in or make it global.</p>

<pre><code>tokens = 10

def spin_wheel():
    global tokens

    ...

def winning():
    global tokens
    ...
</code></pre>

python function