while distance[0][0][0] == '*':
for i in range(0,3):
for j in range(0,3):
if distance[i][j][0] != '*':
k = distance[i][j][0]
for i in range(0,3):
for j in range(0,3):
distance[i][j][k] = 0
In here there are two i
s and j
s. I think this is the part causing the problem. Try to rename them because it affects the output.
So the bottom part should look like this.
k = distance[i][j][0]
for m in range(0,3):
for n in range(0,3):
distance[m][n][k] = 0
This is your code.
distance = [[[0 for k in range(10)] for j in range(3)] for i in range(3)]
distance[0][0][0] = '*'
distance[0][1][0] = 2
distance[0][2][0] = 3
distance[1][0][0] = 4
distance[1][1][0] = 5
distance[1][2][0] = 6
distance[2][0][0] = 7
distance[2][1][0] = 8
distance[2][2][0] = 9
for i in range(0,3):
for j in range(0,3):
if distance[i][j][0] == '*':
for k in range(1,10):
distance[i][j][k] = 1
if distance[0][0][0] == '*':
for i in range(0,3):
for j in range(0,3):
if distance[i][j][0] != '*':
k = distance[i][j][0]
for i in range(0,3):
for j in range(0,3):
distance[i][j][k] = 0
print (distance)
When there are same iteration variables:
>>>[[['*', 1, 0, 1, 0, 1, 1, 0, 0, 0], ... ]
After you rename them:
>>>[[['*', 1, 0, 0, 0, 0, 0, 0, 0, 0], ...]
I changed while
to if
to see changes in distance
.