Luke Taylor
Luke Taylor

Reputation: 9561

Problems with Game Of Life in python

I'm working on Conway's Game of Life in python 2.7, and I'm getting an error I don't understand. In my algorithm to get the number of neighboring tiles that are True, I'm getting an index error.

if column < thesize:
    if board[row][column+1] == True:
        adjacents += 1
return adjacents

thesize is a variable used for generating the 2D grid, so that first line should prevent the error... But it doesn't. The full code is here, can anyone point out my mistake? If the link doesn't work, please let me know.

Upvotes: 0

Views: 269

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798706

A sequence with a length of n has a maximum element index of n - 1. Nonetheless you're trying to access element n - 1 + 1, which doesn't exist.

Upvotes: 3

Related Questions