Python alter external variable from within function
<p>When I run this it works, but it says </p>

<pre><code>"name 'select_place' is assigned to before global declaration"
</code></pre>

<p>When I get rid of the second global, no comment appears, but as select_place is no longer global it is not readable (if selected) in my last line of code. 
I'm really new to python, ideally I'd like a way of not using the global command but after searching i still can't find anything that helps.  </p>

<p>My code:</p>

<pre><code>def attempt(x):
    if location =='a':
         global select_place
         select_place = 0
   if location =='b'
        global select_place
        select_place = 1

place = ([a,b,c,d])
</code></pre>

<p>This is the start of some turtle graphics </p>

<pre><code>def Draw_piece_a(Top_right):
    goto(place[select_place])
</code></pre>

<p>You need to declare the variable first, additionally the function code can be made clearer:</p>

<pre><code>select_place = False
def attempt(x):
    global select_place
    if location == 'a':
        select_place = 0
    elif location == 'b':
        select_place = 1
</code></pre>

<p>Also, there is no return value for <code>attempt()</code>, is this what you want?</p>

python