Constantly says "Oops, that's not even in the ocean."


#1

I've made it to 14/19 and Codecademy isn't detecting a problem, but every time I run the code (hit or miss), it results with the hit or miss then "Oops, that's not even in the ocean".

Code:

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

# Write your code below!
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)

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

elif board[guess_row][guess_col] == 'X' :
    print "You guessed that one already."

result :

 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: 2
Guess Col: 3
1
0
You missed my battleship!
O O O O O
O O O O O
O O O X O
O O O O O
O O O O O
Oops, that's not even in the ocean.
None

#2

I don't think you included all your code here. Could you add the rest?


#3

Just checked through - that's all I've got!


#4

Did you ever adjust your guess to your human input?

Remember computers start at 0 and humans normally start counting at 1 so you need to adjust for that difference.

Also take a look at this code.


#5

Ah thanks - just adjusted both and they work fine now! (: