This question already has an answer here:
Can anyone explain to me why I still get an error?
board = [['#', '#', '#'],['#', '#', '#'],['#', '#', '#']]
def player_1(board):
a = int(raw_input('Choose position 1-9\n'))
if a == 1 or 2 or 3:
if board[0][a-1] == '#':
board[0][a-1] = 'x'
else:
print 'Move invalid, place is taken.'
player_1(board)
if a == 4 or 5 or 6:
if board[1][a-4] == '#':
board[1][a-4] = 'x'
else:
print 'Move invalid, place is taken.'
player_1(board)
if a == 7 or 8 or 9:
if board[2][a-7] == '#':
board[2][a-7] = 'x'
else:
print 'Move invalid, place is taken.'
player_1(board)
When my raw_input = 4, I get this error message:
if board[0][a-1] == '#':
IndexError: list index out of range
Why does it not skip the first if statement?
Aucun commentaire:
Enregistrer un commentaire