# Bad Aim! Passed in fine, still incorrect though

#1

``````This is passed in fine, but it still continually prints out the "Oops, that's not even in the ocean." Line and never goes into the else statement that prints out that the player missed and corrects the map to compensate for that. Much help would be appreciated. Thank you!!

from random import randint

board = []

for x in range(0, 5):
board.append(["O"] * 5)

def print_board(board):
for row in board:
print " ".join(row)

print_board(board)

def random_row(board):
return randint(0, len(board) - 1)

def random_col(board):
return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

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

#2

What is the error message that this exercise is giving you? Any external information would also be helpful... Thanks!

#3

Your code works just fine for me. Don't forget indexes start from zero, so acceptable numbers for input are [0,1,2,3,4].

#4

The error message I get is like this:
O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
Guess Row: 5
Guess Col: 5
2
4
Oops, that's not even in the ocean.
None

So that it never actually goes into the if statement but just defers to the elif statement. By Codeacademy it works fine but it always goes to that elif no matter what

#5

OOHH! Actually just figured out what was wrong with my code. Thanks for everyone's help!

#6

I'm also experiencing the same error while trying to debug my battleship programme.I'm entering values out of range to see if my 'if guess_row not in range(5) and guess_col not in range(5): gives the output "OOPS that's not in the ocean"...anyone please help me to debug the programme.above is the snapshot of my session.

#7

how to get rid of this,i am having the same problem