Where is the error?



Shows error message : "Make sure to enter a col and row that is on the board!"

As per my knowledge, the code should work fine. Moreover the incorrect guess numbers are not replaced by "X".

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)


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

def random_col(board):
    return randint(1, len(board))

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!"
    print "You missed my battleship!"


Your error message mentions user input, so relevant information is what user input you gave it when getting that error message


i always gave an input lying between 0 and 5 for both rows and columns. Still it shows the error.


so 1 2 3 4 only (between)? Or including both ends? That would be 0 1 2 3 4 5 which is 6 rows/cols when there are only 5

You're re-using the variables where the guesses are stored, so they no longer refer to what their names suggest that they refer to


to be on a safe side i enter 3 and 3. it still shows the error. what now?


You overwrote the input, so those variables no longer refer to coordinates that are within the board


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