--Originally published at Quirino´s Projects
Made a TicTacToe in python
NOTE: I do not recomend using this code since indenting in wordpress is a hard task, instead, download it from my GitHub repo;
https://github.com/QuirinoC/TicTacToe.py
''' Juan Carlos Quirino Carrasco ----------------------------------------------------- Tried to do all functions as simple as possible Maybe later i will do a more beautiful change_turn(), user_input() and win(),tie() ----------------------------------------------------- You are free to user, change and everything, just dont copy and present like yours, you can, but give credit ''' def table(): #this function creates a 3x3 table ''' - / - / - - / - / - - / - / - ''' board = [] for i in range(3): board.append(["-"]*3) return board def print_board(board): '''This function prints the board in pretty formated way''' for column in board: print () for i in column: print (i, end=" ") print ("\n") ''' This is incorrect since it would print the same column 3 times ''' #print (" ", board_[i] , end=" / ") #print (board_[i] , end=" / ") #print (board_[i]) #print() def win(board): global turn ''' This function checks if someone wins Must be called every time someone writes ''' a = board[0][0] b = board[0][1] c = board[0][2] d = board[1][0] e = board[1][1] f = board[1][2] g = board[2][0] h = board[2][1] i = board[2][2] #Add to test for not being '-' DONE ''' 0 1 2 0 a / b / c 1 d / e / f 2 g / h / i ''' if \ (a == b and b == c and b != "-") or \ (d == e and e == f and e != "-") or \ (g == h and h == i and h != "-") or \ \ (a == d and d == g Continue reading "TicTacToe.py"