theBoard = {'top left': ' ', 'top middle': ' ', 'top right': ' ',
'center left': ' ', 'center middle': ' ', 'center right': ' ',
'bottom left': ' ', 'bottom middle': ' ', 'bottom right': ' '}
def printBoard(board):
print(board['top left'] + '|' + board['top middle'] + '|' + board['top right'])
print('-+-+-')
print(board['center left'] + '|' + board['center middle'] + '|' + board['center left'])
print('-+-+-')
print(board['bottom left'] + '|' + board['bottom middle'] + '|' + board['bottom right'])
turn = 'X'
for i in range (9):
printBoard(theBoard)
print('Turn for ' + turn + '.Move on which space?')
move = input()
theBoard[move] = turn
if turn == 'X':
turn = 'O'
else:
turn = 'X'
printBoard(theBoard)发布于 2019-03-02 03:57:57
我想你只是把缩进搞错了:
theBoard = {'top left': ' ', 'top middle': ' ', 'top right': ' ',
'center left': ' ', 'center middle': ' ', 'center right': ' ',
'bottom left': ' ', 'bottom middle': ' ', 'bottom right': ' '}
def printBoard(board):
print(board['top left'] + '|' + board['top middle'] + '|' + board['top right'])
print('-+-+-')
print(board['center left'] + '|' + board['center middle'] + '|' + board['center left'])
print('-+-+-')
print(board['bottom left'] + '|' + board['bottom middle'] + '|' + board['bottom right'])
turn = 'X'
for i in range (9):
printBoard(theBoard)
print('Turn for ' + turn + '.Move on which space?')
move = input()
theBoard[move] = turn
if turn == 'X':
turn = 'O'
else:
turn = 'X'
printBoard(theBoard)https://stackoverflow.com/questions/54951424
复制相似问题