Python Forum

Full Version: Text Based Tic Tac Toe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:
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.
(Nov-11-2017, 03:13 PM)heiner55 Wrote: [ -> ]Study this: http://inventwithpython.com/chapter10.html
or that: http://www.practicepython.org/solution/2...tions.html

Thank you, but im looking for why my code didnt run as intended, not how to make one, as they both dont have the same concept as mine.
Quote:why my code didnt run as intended, not how to make one

Without showing us your code, we can not help.