This code is part of a Tic-Tac-Toe script, in which a player inputs a number based on what space they wish to place their marker. To test the script out, I only wrote code for board[1].
board = ['','','','','','','','','','']
count = 0
turn_counter = 1
def print_board():
print(board[1] + " |" + board[2] + " |" + board[3])
print("--+--+--")
print(board[4] + " |" + board[5] + " |" + board[6])
print("--+--+--")
print(board[7] + " |" + board[8] + " |" + board[9])
def main_operator(board_val):
global turn_counter
global count
if turn_counter == 1:
board_val = 'X'
count = count + 1
turn_counter = turn_counter + 1
elif turn_counter == 2:
board_val = 'O'
count = count + 1
turn_counter = turn_counter - 1
def game_start():
user_input = int(input("Player " + str(turn_counter) + ", choose a space"))
if user_input == 1:
main_operator(board[1])
for i in range(9):
print_board()
game_start()
However, the main_operator() function does not change the value for board[1], instead leaving it unchanged. What am I doing wrong?