I have tried creating a tic tac toe game using Python but it is not working. Can someone please take a look at it and tell me if I made a mistake?
When I run the game it only prints the board and then asks for a number for x. Once I type that, the game prints a board and closes.
def tic_tac_toe():
end = False
win_combinations = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))
board = [1,2,3,4,5,6,7,8,9]
def draw():
print(board[0], board[1], board[2])
print(board[3], board[4], board[5])
print(board[6], board[7], board[8])
print()
def player_option_check():
while True:
try:
arg1 = input("please enter number")
arg1 = int(arg1)
if arg1 in range(0,9):
return arg1 - 1
else:
print ('not a number on he board')
except:
print('this is not a number re try')
def player_X():
choice = player_option_check()
board[choice] = 'x'
def player_y():
choice = player_option_check()
board[choice] = 'y'
def check_winner_x ():
for a in win_combinations:
if board[a[0]] == board[a[1]] == board[a[2]] == 'o':
print('player o wins')
return True
if board[a[0]] == board[a[1]] == board[a[2]] == 'x':
print('player x wins')
return True
for a in range(9):
if board[a] == "X" or board[a] == "O":
count += 1
if count == 9:
print("The game ends in a Tie\n")
return True
while not end:
draw()
end = check_winner_x
if end == True:
break
else:
player_X()
draw()
end = check_winner_x
if end == True:
break
else:
player_y()
draw()
if end==True:
again_play=print(input("would u like to play again press (y/n)"))
again_play == "y"
tic_tac_toe()
else:
print('thanks for playing')
break
tic_tac_toe()
So can you please help me find the mistake in my code. This is in Python 3.