# Battleship! Hide

#1

why there is a different between this lines?

``````len(board) - 1
len(board[0]) - 1

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

def random_col(board):
return radint(0, len(board[0]) - 1)``````

#2

we have a multi-dimensional lists as our board, lets say outer and inner list. The outer list contain the rows, the inner list the columns, so accessing any random row (board[0]) will give you access to the columns, this is particular useful if you board doesn't have as much columns as row (6x8 board for example)

#3

now it's clear, Thanks! but when i do this simple example, you can see that print len(board) - 1 give me 7 and in my row i need to get 4 see the function:

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

give 7 need to give 4 no?

``````board = [['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']
,['O', 'O', 'O', 'O', 'O']]

print len(board) - 1
print len(board[0])-1``````

print
7
4

#4

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