IndexError list index out of range

python

#1

hey,

i’ve got an error with my code which i cant figure out im new to python!
This is my code.

def winner(grid):
    for across in range(4):
        row = across * 4
        line = grid[row] + grid[row+10] + grid[row+20] + grid[row+30]
        if line == "XXXX" or line == "OOOO":
            return True

    for down in range(4):
        line = grid[down] + grid[down+40] + grid[down+80] + grid[down+12]
        if line == "XXXX" or line == "OOOO":
            return True

    line = grid[00] + grid[50] + grid[10] + grid[15]
    if line == "XXXX" or line == "OOOO":
            return True

    line = grid[30] + grid[60] + grid[90] + grid[12]
    if line == "XXXX" or line == "OOOO":
            return True

This is the area of the code which has an error but i dont understand it.

IndexError: list index out of range

Please help!

Thanks in advance


#2

It should be pretty easy to figure out what that error message means by googling. It’s already fairly plainly worded though.