Board indexing question


#1

Why is board indexed at 0 in the rand_col function but not also in the rand_row function?


FAQ: Learn Python - Battleship - And Seek
#2

I have the exact same question. Looking forward to hear from someone about this question.


#3

Actually, both rows and columns are zero-indexed. If you are referring to this,

rand_col = randint(0, len(board[0] - 1))

it has to do with a non-square board having more or less columns than rows. We cannot set up the rows with the correct number of columns without knowing their length.


#4

Here is the solution :slight_smile:

https://www.codecademy.com/en/forum_questions/50a3cc912010f99cc7005625

Thank for your reply too.


#5

You’re welcome. Sorry for all the typos… Need new glasses.


#6

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