Hi Bros and Sissys,

I have successfully passed through 7/19)Hide...This is my below program.

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):
    return randint(0,len(board)-1)
def random_col(board):
    return randint(0,len(board)-1)   

But, can anyone explain me why do we use this return randint(0,len(board)-1) statement and what is the exact operation taking place over there?

Your words for this quest will be much appreciated.


randint is an abbreviation for random integer (integer = non decimal number)

len(board) is 5, minus one is 4. so in your case you have:

return randint(0,4)

so possible values: 0,1,2,3,4. which perfectly matches with the indexes of your board


But, why do we use it from 0 to 4 but not 1 to 5...
Can we use the no from 1 to 5?


because lists are zero indexed based

with the right tweaking, yes you can. But first finish the battleship, then afterwards you can do such tinkering (that is at least my recommendation)


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