7/13 Battleship!


#1

Can someone help me with understanding those lines verbally

1.
def random_row(board):
return randint(0, len(board) - 1)
2.
def random_col(board):
return randint(0, len(board[0]) - 1)

  1. randint(0, len(board) - 1)
    len board = 5
    len board - 1 = 4 ?

  2. randint (0, len(board[0]) - 1)
    len(board[0]) = 5
    len(board[0]) - 1 = 4 ?

yes?


#2

@rubysurfer09367

Yup, you got it!

0-4

Now remember that 0 does count so you have 5 indexes.

Randint gives us a number including the beginning and end. So unlike range which gives us a number from the begging up to the end.

range(0, 5) = 0-4
randint(0, 4) = 0, 4