Indexing in 11. Danger, Will Robinson!


#1




https://www.codecademy.com/courses/python-beginner-en-4XuFm/1/2?curriculum_id=4f89dab3d788890003000096

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

else:
    print "You missed my battleship!"
    board[guess_row-1][guess_col-1] = "X"
    print_board(board)


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?


#2

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


#3

Thanks, that would be the best solution for that!


#4

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


#5