FAQ: Learn Python - Battleship - Hide

Ok. Got it.

That’s it! Thank you! I was focusing on the output and somehow forgot to look at the bigger picture and missed the fact that I’m dealing with functions here.

1 Like


in this image you can see what I believe is wrong again with the code, similarly to what cluesis found. I don’t know why it was changed from when i wrote and submitted it but i dont think that should work.

I workshopped this one for a while. I haven’t had issue before, but found that I needed to call both random numbers as a different variable for it to read. I also did not call them in the board function and just printed them for my result. Not sure why but this is the code that ran for me.

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)

Add your code below!

def random_row(board_in):
r = randint(0, len(board_in) - 1)
print r
return r
def random_col(board_in):
c = randint(0, len(board_in) - 1)
print c
return c