Danger, Will Robinson!


#1

I am not getting where the error is
Here is the last part of the program:

if guess_row == ship_row and ship_row == guess_row:
print"Congratulations! You sank my battleship!"
else:
print "You missed my battleship!"
board[guess_row][guess_col] == "X"
print_board(board)

ERROR:
O O O O O
O O O O O
O O O O O
Guess Row: 5
Guess Col: 4
4
2
You missed my battleship!
Traceback (most recent call last):
File "python", line 33, in
IndexError: list index out of range


#2

lists are zero indexes based, so if the list is 5 long, the indexes are 0,1,2,3,4 so the 5 is out of range


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.