Question: I need a flowchart for this code import random #tictactoe function def TicTacToe(): cell = [None] + list(range(1, 10)) #winning combinations winning = [ (1,
I need a flowchart for this code
import random #tictactoe function def TicTacToe(): cell = [None] + list(range(1, 10)) #winning combinations winning = [ (1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 4, 7), (2, 5, 8), (3, 6, 9), (1, 5, 9), (3, 5, 7), ]
#print the cell def display(): print(cell[1], cell[2], cell[3]) print(cell[4], cell[5], cell[6]) print(cell[7], cell[8], cell[9]) print()
#get user move def getMove(): while True: try: a = int(input()) if a in cell: return a else: print(" Invalid move. Try again") except ValueError: print(" That's not a number. Try again")
#check winner def isOver(): for a, b, c in winning: if cell[a] == cell[b] == cell[c]: print("Player {0} wins! ".format(cell[a])) print("Congratulations! ") return True if 9 == sum((pos == 'X' or pos == 'O') for pos in cell): print("The game ends in a tie ") return True
#if not game over get another move for player in 'XO' * 9: display() if isOver(): break if(player=='X'): #user play print("Player {0} move".format(player)) print("Player {0} pick your move.. for hint enter 'a':".format(player)) cell[getMove()] = player print()
if(player=='O'): #computer print("Player {0} move".format(player)) while (True): a=random.randint(0,9) if a in cell: break cell[a] = player print()
while True: TicTacToe() if input("Play again (y/n) ") != "y": break
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
