class tictactoe """management of tic-tac-toe game (does not do strategy"" def init (self) """start new game "" self board for in range( self player def mark(selfij) """put an or mark at position ( ,jfor next player turn "" if not ( < < and < < ) raise valueerrorinvalid board position if self board[ ][ ! raise valueerrorboard position occupied if self winneris not none raise valueerrorgame is already complete self board[ ][jself player if self player = self player else self player def is win(selfmark) """check whether the board configuration is win for the given player "" board self board local variable for shorthand return (mark =board[ ][ =board[ ][ =board[ ][ or row mark =board[ ][ =board[ ][ =board[ ][ or row mark =board[ ][ =board[ ][ =board[ ][ or row mark =board[ ][ =board[ ][ =board[ ][ or column mark =board[ ][ =board[ ][ =board[ ][ or column mark =board[ ][ =board[ ][ =board[ ][ or column mark =board[ ][ =board[ ][ =board[ ][ or diagonal mark =board[ ][ =board[ ][ =board[ ][ ]rev diag def winner(self) """return mark of winning playeror none to indicate tie "" for mark in xo if self is win(mark) return mark return none def str (self) """return string representation of current game board "" rows join(self board[ ]for in range( ) return \ \ join(rowscode fragment complete python class for managing tic-tac-toe game