Вот моя программа:
Код: Выделить всё
grid = [['0','1','2','3'],['1','_','_','_'], ['2','_','_','_'],['3','_','_','_']]
print("Tic-Tac-Toe")
for row in grid:
print(row)
for row in grid:
for cell in row:
if cell != '_':
valid_input = False
while not valid_input:
x_x = int(input("Choose x-coordinate for x: "))
x_y = int(input("Choose y-coordinate for x: "))
if x_x < 1 or x_x > 3 or x_y < 1 or x_y > 3:
print("Invalid input for x. Please try again.")
elif grid[x_x][x_y] != '_':
if '_' in grid == False:
break
else:
print("The place is occupied. Choose another place for x.")
else:
grid[x_x][x_y] = 'x'
for row in grid:
print(row)
valid_input = True
valid_input = False
while not valid_input:
o_x = int(input("Choose x-coordinate for o: "))
o_y = int(input("Choose y-coordinate for o: "))
if o_x < 1 or o_x > 3 or o_y < 1 or o_y > 3:
print("Invalid input for o. Please try again.")
elif grid[o_x][o_y] != '_':
if '_' in grid == False:
break
else:
print("The place is occupied. Choose another place for o.")
else:
grid[o_x][o_y] = 'o'
for row in grid:
print(row)
valid_input = True
Подробнее здесь: https://stackoverflow.com/questions/790 ... -is-filled