Nov-11-2017, 06:21 AM
I've been given an assignment that utilises the random function in python to make a simple game. I've chosen to make a text based tic tac toe, player vs AI game. Ive gotten the board up by:
Then I would have all the contents of 'x' replaced with '', and have the user input from 1 - 9 and verify if that slot has already been taken, and if not replace it with an 'x', but somehow when I print out Layer1 to Layer3, it still shows the values of 1 to 9 even though it says that the array has been replaced.
I should also state that this is in 2.7 and this is occuring inside a non repeating function.
x = ['1','2','3','4','5','6','7','8','9'] #values to be inserted to the board per layer from left to right. Layer1 = '[ ' + x[0] + ' ] ' + ' [ ' + x[1] + ' ] ' + ' [ ' + x[2] + ' ]' Layer2 = '[ ' + x[3] + ' ] ' + ' [ ' + x[4] + ' ] ' + ' [ ' + x[5] + ' ]' Layer3 = '[ ' + x[6] + ' ] ' + ' [ ' + x[7] + ' ] ' + ' [ ' + x[8] + ' ]' print(Layer1 + '\n' + Layer2 + 'n' + Layer3)
Then I would have all the contents of 'x' replaced with '', and have the user input from 1 - 9 and verify if that slot has already been taken, and if not replace it with an 'x', but somehow when I print out Layer1 to Layer3, it still shows the values of 1 to 9 even though it says that the array has been replaced.
I should also state that this is in 2.7 and this is occuring inside a non repeating function.