What does list index out of range mean?


#1

Question

What does list index out of range mean?

Answer

We haven’t done any error handling in our code yet to prevent it from crashing if you enter invalid input, so be sure to only provide valid row and column. Remember, indexes start from 0 in Python, so we have rows and columns numbered 0 through 4.
If you guess something like row 5 and col 5, it will give you an index out of range error because board has no index 5.


FAQ: Learn Python - Battleship - Danger, Will Robinson!