# Bad practice (verging on wrong answer) in Battleship Hide! (13/7) unit

#1

I don't like the "prompted" answer for Battleship Hide! unit- it works for this particular assignment, but will lead to insidious, hard-to-track bugs if generalized. Since this course seems to be geared to beginners, I believe you're doing them a disservice.

You are asked to generate a random row and column index for a given board. The instructions prompt you to use

``randint(0,len(board)-1)``

to generate both a random row and column number. In this particular case, we have a 5x5 board, so using

``len(board)``

will return correct results for both a randomly chosen row or a randomly chosen column.

The problem is that in the general case, the number of rows will not equal the number of columns!

``len(board)``

is the number of rows in the board, and

``len(board[0])``

is the number of columns in the first row (which we will have to hope is the same as in any other row!)

I think the "prompted" answer should be:

Use

``len(board)``

for the number of rows in the board, and

``len(board[0])``

for the number of columns- perhaps with a discussion about the distinction, or even changing the board size so it's not square to force the discussion.

Up to this point, however, I think this is a great resource for those learning to code or learning a new language. Keep it up, please!

EDIT: I guess I spoke too soon- the next step (and Seek!) does use the correct expression

``len(board[0])``

for the number of columns. However, it's kind of just slipped in when one progresses to the next level, and I think it would be better to either call attention to it- either before (so the student generates the correct code) or after (so the student understands why

``len(boards[0])``

is the correct expression for the number of columns.