Ceci est mon code:Comment remplir un tableau 2D en Python?
empty = ' '
board = [[empty, empty, empty], [empty, empty, empty], [empty, empty, empty]]
def print_board():
for idx, val in enumerate(board):
print(val)
def board_update(x,y,player):
board[x:y] = player;
game_is_running = True
player = 'x'
print_board()
while game_is_running:
if player == 'x':
print ('x turn')
ver = int(input('input vertical of x '))
hor = int(input('input horizontal of x '))
board_update(ver, hor, player)
player = 'o'
print_board()
if player == 'o':
print ('o')
vertical = int(input('input vertical of o '))
horizontal = int(input('input horizontal of o '))
Chaque fois que je lance le code, il met juste la lettre comme ceci:
[' ', ' ', ' ']
x
[' ', ' ', ' ']
[' ', ' ', ' ']
Comment puis-je faire ressembler à ceci:
[' ', ' ', ' ']
[' ', x , ' ']
[' ', ' ', ' ']
'board [x: y] = player' ne fait pas ce que vous pensez. Vous voulez 'board [x] [y] = player'. – L3viathan