Hide...(why are we using len(board) - 1?


#1


https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/7?curriculum_id=4f89dab3d788890003000096


Hi,
I have completed the exercise but don't get why we are using len(board) - 1 here.

What does the -1 achieve exactly?


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)

random_row(board)
random_col(board)


#2

Our board is a (multi-dimensional) list.

the list list has 5 items, so the length is 5. However, lists are zero indexed based so the indexes are:

0, 1, 2, 3, 4

Does that answer your question?


#3

Yes it does. Thank you!!


#4