Python code
Python code
# Check columns
for col in range(len(board[0])):
if board[0][col] == board[1][col] == board[2][col] and board[0][col] != '
': # If all elements in the column are the same and not empty
return True # Return True, indicating a win
# Check diagonals
if board[0][0] == board[1][1] == board[2][2] and board[0][0] != ' ': # If all
elements in the diagonal are the same and not empty
return True # Return True, indicating a win
if board[0][2] == board[1][1] == board[2][0] and board[0][2] != ' ': # If all
elements in the diagonal are the same and not empty
return True # Return True, indicating a win
while True:
print_board(board) # Print the current board
try:
row = int(input(f"Player {player}, enter row number (0, 1, 2): ")) #
Get user input for row
col = int(input(f"Player {player}, enter column number (0, 1, 2): "))
# Get user input for column
except ValueError:
print("Invalid input! Please enter a number.") # Handle invalid input
continue
if row < 0 or row > 2 or col < 0 or col > 2: # If input is out of bounds
print("Invalid input! Please enter a number between 0 and 2.") # Print
error message
continue