I am trying to do print a checkerboard using arrays and without importing any packages like Numpy. The code should print back
X 0 X 0 X 0 X 0
0 X 0 X 0 X 0 X
X 0 X 0 X 0 X 0
0 X 0 X 0 X 0 X
X 0 X 0 X 0 X 0
0 X 0 X 0 X 0 X
X 0 X 0 X 0 X 0
0 X 0 X 0 X 0 X
This is what I have written
Checkerboard = [[0]*8 for i in range(8)]
for i in Checkerboard:
p = 0
q = 0
for j in i:
if q % 2 == 0 and p % 2 == 0:
Checkerboard[i][j] = "X"
elif q % 2 == 1 and p % 2 == 1:
Checkerboard[i][j] = "X"
p += 1
for i in Checkerboard:
for j in Checkerboard:
print(j, end='')
print('')
But it keeps getting the error:
Checkerboard[i][j] = "X"
TypeError: list indices must be integers or slices, not list
Can anyone help me solve the problem or give some tips?
(This is a hw assignment)