0

he following code gives the error UnboundLocalError: local variable 'currentpl' referenced before assignment:

if user_choice == 0:
    currentpl = 1
elif user_choice == 1:
    currentpl = 2
while gameover(num_sq):
    if currentpl == 1:
        pick = getPlayerPick(num_sq)
        while not validPlay(pick, num_sq):
            pick = getPlayerPick(num_sq)
        makePlay(pick, player_col[currentpl])
    if currentpl == 2:
        pick = computerSelection(num_sq)
        makePlay(pick, player_col[currentpl])
    currentpl = togglePlayer(currentpl)
if currentpl == 2:
    return "User"
return "Computer"

How can I fix this? Thanks for any help!

2
Contributors
1
Reply
18
Views
2 Years
Discussion Span
Last Post by snippsat
1

Is this all of your code?
There are missing several function definition here.
You never use return without a function.

Post all of you code and full Traceback.
Or at least code we can run that give this Traceback.
Traceback always give you linenumber where error occur.

Here is a explaintion of UnboundLocalError

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.