Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop the beginnings of a tic-tac-toe program. Display the board; ask the user

ID: 3847704 • Letter: D

Question

Develop the beginnings of a tic-tac-toe program. Display the board; ask the user for a board position to place an 'X'; if the position is currently empty, place the 'X' in that position. You will need two functions: displayBoard(board): This function will display the board to the screen and return the number of Xs displayed. filled(board): This function returns True if there are no empty spaces on the board, False otherwise Run the program to see the I/O Be sure to use the template given or your program will not pass the tests

Explanation / Answer

def main():
board = ['-','-','-','-','-','-','-','-','-']
display(board)
print("Enter the position to place X")
pos = input();
if pos < 1 or pos > 9:
print("invalid input")
return
board[pos-1] = 'X'
display(board)
flag = filled(board)
print(flag)
  
def display(board):
numX = 0;
print(' | |')
print(' ' + board[0] + ' | ' + board[1] + ' | ' + board[2])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[3] + ' | ' + board[4] + ' | ' + board[5])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[6] + ' | ' + board[7] + ' | ' + board[8])
print(' | |')
for num in range(0,8):
if board[num] == 'X':
numX = numX + 1
  
print("Num of X ",numX)
  
def filled(board):
fill = True
for num in range(0,8):
if board[num]=='-':
fill = False
return fill
  
if __name__ == "__main__":
main()