Danger, will robinson


I think I have done this exercise correctly, however the following error message keeps appearing after I enter data on the console:

Oops, try again. Make sure to enter a col and row that is on the board!

Can someone explain what I'm doing wrong?

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


It's suggesting that the user input (which you haven't said what it was) isn't valid


Is there a specific user input?


wait hold on it did just let me guess a load of times and then I guessed right


I suspect anything that's ON the board would do it, as opposed to outside it - for which there isn't any code yet


You have to change the location that you have guessed with "X".So you have to make appropriate changes in the Board List ...so use board[guess_row][guess_col] = "X" so whatever location you guessed it will print "X" over there


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