Battleship! Debugging. Not sure where to place elif statement


#1



"NOT AGAIN + TEST RUN part of the exercise BATTLESHIP!"

I should be getting the message "oops thats not even in the ocean." when I input something outside of the range.
I feel like I might have messed up the logic of the conditionals but I am not sure how to fix it in a way to ensure that all the functions of the game are enabled.

This is my code:

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

# This is the errormessage I get

This is the error message I get when I input numbers outside of the range:
`Traceback (most recent call last):
  File "python", line 32, in <module>
IndexError: list index out of range`


#2

# handles correct guess
if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
# handles incorrect guesses
else:

your if statement handles the correct guesses, and your else the incorrect guesses. Is checking if the user guessed that one already a correct or incorrect guess?


#3

Your point is clear. I sort of had this in mind but when the instructions asked for an elif statement to see if the guess had already been made, I got confused as to where to place the elif statement without interfering with the flow.


#4

yea, its a bit confusing.

but you added this in the previous exercise:

if guess_row not in range(5) or guess_col not in range(5):
        print "Oops, that's not even in the ocean."

and then this exercise says: lets handle another incorrect guess, which sort of hints it has to be after this if statement


#5

I got it to work now. Thank you for the help!


#6