How do I get rid of local variable referenced before assignment error?
<p>I'm trying to make a simple program that generates a board on which you move around as X. 
Code:</p>

<pre><code>from msvcrt import getch
import os

board = []

for x in range(20):
    board.append(["O"] * 20)

def print_board(board):
    for row in board:
        print " ".join(row)

def keys(coordx, coordy):
    global coordY
    global coordX
    key = ord(getch())
    if key == 97:
        coordx -= 1
    elif key == 100:
        coordx += 1
    elif key == 115:
        coordy -= 1
    elif key == 119:
        coordy += 1

def play(coordx, coordy):
    global coordY
    global coordX
    while True:
        board[coordx][coordy] = "X"
        print_board(board)

        keys(coordx, coordy)

        os.system('cls')

coordX = 10
coordY = 10

play(coordX, coordY)
</code></pre>

<p>Every time i want the program to change the value of coordX or coordY i get UnboundLocalError: local variable coordY/coordX refferenced before assignment. I tried different methods - making variables global, making arguments for functions instead of using the variables while defining functions and nothing worked.</p>

<p>Once you call <code>play</code>, you never make any assignments to either <code>coordX</code> or <code>coordY</code>, which would explain why they never change.</p>

python python-2.7