Indexing in 11. Danger, Will Robinson!


I get this message:
Oops, try again. You're updating 'guess_row - 1' and 'guess_col - 1' instead of 'guess_row' and 'guess_col'.

    print "You missed my battleship!"
    board[guess_row-1][guess_col-1] = "X"

As in the written Example the code print board[2][3] returns the 3rd row and the 4th column, because the indizes for that are 2 and 3.
So in my opinion I have to subtract 1 from each guess to get the index. As the indexing starts with 0 it will be always minus 1 of the guessed row and column. With board[guess_row][guess_col] = "X" I will not get the guessed row and column.

Am I right with that issue?


if you want to compensate for the fact that list are zero indexed based, subtract one from the user input:

guess_row =int(raw_input("row: ")) - 1

this allows the user to enter 1-5, and matches your 0-4 indexes of your list

When programming, the easiest thing to manipulate is the user data


Thanks, that would be the best solution for that!


yes, if the user enters 0, it becomes -1, which will raise an error that this shot is not in the ocean, perfect