Error in 11. Danger, Will Robinson!


#1

I succesfully completed Error in 11. Danger, Will Robinson!!

The problem is the following:

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

I have found 2 errors in 11:

  1. If I use another code that doesn't work, if I hit the ship, it says that the exercise is correct (and is not).
  2. If I put X at guess_row and guess_col, if I choose for example 1 and 4, the board will draw the X at row 2, column 5.

It think that the solution would be this:

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

That way, the board will put the X in the first row, fourth column with said guess.

Thanks for the course!

PS: I have moved the - 1 to the input, which works better:

guess_row = int(raw_input("Guess Row:")) - 1
guess_col = int(raw_input("Guess Col:")) - 1


#2

Which is correct. Row 2 is actually index 1, and row 5 is actually index 4. Remember, lists are zero-indexed, meaning the first index is 0.


#5