I have this code that doesn't work the way I expect it to. I'm trying to make a grid. It should output the tuple from the list, but it's stuck on the first number.
Is there a problem with my logic?
row = []
grid = []
for y in range(0,3):
row.append((0,0))
for x in range(0,3):
grid.append(row)
for y in range(0, 3):
for x in range (0, 3):
print (x,y)
grid[x][y] = (x,y)
print (grid[x][y])
print ("\nTesting:")
for y in range(0, 3):
for x in range (0, 3):
print (grid[x][y])
What it outputs is this:
0 0
(0, 0)
1 0
(1, 0)
2 0
(2, 0)
0 1
(0, 1)
1 1
(1, 1)
2 1
(2, 1)
0 2
(0, 2)
1 2
(1, 2)
2 2
(2, 2)
Testing:
(2, 0)
(2, 0)
(2, 0)
(2, 1)
(2, 1)
(2, 1)
(2, 2)
(2, 2)
(2, 2)