View the step-by-step solution to:

This is my Python Tic Tac Toe code I am supposed to add check for winner I can't figure out how! ROWS = 3 COLS = 3 board = [["*"]* COLS for...

This is my Python Tic Tac Toe code

I am supposed to add check for winner

I can't figure out how! please help!


ROWS = 3

COLS = 3

board = [["*"]* COLS for i in range(ROWS)]


def TicTacBoard(board):

  for row in range(0,ROWS):

    for col in range(0,COLS):

      if col <= 1:

        print (" "+board[row][col]+" |",end="")

      else:

        print(" "+board[row][col]) 

    if row <= 1:

      print("-----------")


def makeMove(player):

  validMove = False

  while not(validMove):

    row = int(input("Enter row of your move between 1 and 3:"))

    col = int(input("Enter col of your move between 1 and 3:"))

    if (1 <= row <=3) and (1 <= col <= 3):

      row = row -1

      col = col -1

      if board[row][col] == "*":

        board[row][col] = player

        validMove = True

      else:

        print("That square is taken. Please try again")

    else:

      print("Both row and column must be between 1 and 3. Please try again")


#main

moves = 0

play = "X"

while moves < 9:

  TicTacBoard(board)

  print("player",play,"your move")

  makeMove(play)

  moves = moves + 1

  if play == "X":

    play = "O"

  else:

    play = "X"

Top Answer

I have made a little changes to you code: 1: Input is now done in main 2: Make... View the full answer

tictac.PNG

Sign up to view the full answer

Other Answers

The output of the program is as follows:  * | * | * -----------  * | * | * -----------  * | * | * player X your move Enter... View the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online