What the H 13. Battleship


#1



if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
else:
if guess_row > 5 or guess_col > 5:
print "Oops, that's not even in the ocean."
elif board[guess_row][guess_col] == "X":
print "You guessed that one already"
else:
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
print_board(board)


It has no errors on the screen but codecademy keeps asking me if I am sure if I put in "You guessed that already" in my elif statement which to me it looks like I have done. Everything else seems to work pretty well


Replace this line with your code.


#2

Is the string exactly the same? What have you done to check if it is? If that wasn't an exact method of comparison, then that's what you need to do.


#3

lol I was missing a period at the end of the "You guessed that one already." statement. Thanks though


#4

Isn't that what I suggested you look for :confused:

It wasn't exactly the same, so an exact method of comparison was required to find a very small difference.


#5

Just a heads up, you should also fix this line:

Your code would allow the number 5, which is not in the range of the board (0-4). It also does not check for negative integer guesses.

You want:

if guess_row not in range(5) or guess_column not in range(5):

which will only allow guesses of 0-4. See lesson "12. Bad Aim"


#6

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