Bad aim


#1



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

My code is throwing this error message?


Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: list index out of range


if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
else: 
    print "You missed my battleship!"
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)


#2

step 4 of the instructions:

After your new if: statement, add an else: that contains your existing handler for an incorrect guess. Don't forget to indent the code!

so this your existing handler:

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)

should be indented so that it is inside else.


#3

Like so?? still not working?

if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
else: 
    print "You missed my battleship!"
    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!"

#4

except now you print twice that the ship is missed

and this line:

board[guess_row][guess_col] = "X"

does it make sense where you currently placed it?


#5

I got it running now thanks :smile:


#6