Question about random_col() and random_row()

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

def random_col(board):
  return randint(0, len(board[0]) - 1)
  1. Why do we subtract one from the board length?
  2. Why do we need the index at the len(board) in random_col?

  1. because lists are zero indexed based, while length starts counting at one
  2. Well, its better. Because this will give us the column, not the row. Yes, currently the board is square, but actually using the column for random_colwill make it easier to make the board rectangle (for example 8 by 4


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