So I do not understand why I am getting this error : Traceback (most recent call last): File "/storage/emulated/0/Android/data/com.coobbi.python/cache/coobbi/tictactoe/tictactoe.py", line 30, in <module> tictactoe() File "/storage/emulated/0/Android/data/com.coobbi.python/cache/coobbi/tictactoe/tictactoe.py", line 18, in tictactoe print(gameboard) ^^^^^^^^^
UnboundLocalError: cannot access local variable 'gameboard' where it is not associated with a value
1|:/data/user/0/com.coobbi.python/app_HOME $
The following is the full code:
space_one = 1
space_two = 2
space_three = 3
space_four = 4
space_five = 5
space_six = 6
space_seven = 7
space_eight = 8
space_nine = 9
player_one = "X"
player_two = "O"
num_choice_p1 = "Please select a number player one"
num_choice_p2 = "Please select a number player two"
invalid = "Please select a free number space on the board"
gameboard = "1|2|3\n_4_|5|6\n_7_|8|9"
def tictactoe():
print("Welcome to tic tac toe!\nPlease choose players.\nPlayer one is X and goes first, while player two is O.\nEach player takes a turn choosing a number to place their X or O. The first player to get three in a row wins! ")
print(gameboard)
print(num_choice_p1)
while True:
p1_choice = int(input())
if 0 < p1_choice < 10:
p1_choice = str(p1_choice)
game_refresh = gameboard.replace(p1_choice,"X")
gameboard = game_refresh
print(game_refresh)
else:
print(invalid)
print()
tictactoe()
Is this an issue with running on Android? I don't understand why it would say it's not defined with a value.