Need help fixing a game I made in Python
<p>I have been set a task to make a fruit machine game in python, however I am facing a small problem, it involves a variable. it is saying that I have referenced the variable before it's assignment, even though I have assigned it. It seems to be reading it as a local variable instead of a global variable. How do i fix this.</p>

<p>This is the part causing the most trouble </p>

<pre><code>Credit = 1

def main(): #the main program
    Credit = Credit - 0.20
    print("Credit remaining = " + Credit) #tells the player the amount of credit remaining
    print("\n *** The Wheel Spins... *** \n") #Spinning the wheel
    print(input("\n (press enter to continue) \n"))
</code></pre>

<h1>error message</h1>

<pre><code>line 19, in main
   Credit = Credit - 0.20
UnboundLocalError: local variable 'Credit' referenced before assignment
</code></pre>

<p>Anytime you want to write to a global variable in another function in python, you should let python know you want to use the global variable. Before the first line of main insert:</p>

<pre><code>global Credit
</code></pre>

python pygame global-variables local-variables