Can anyone point me to what's wrong?
I got stuck on newGrid.setValue(n[k][0], n[k][1], List[k]) trying to feed the values of each x/y of each coord into a different function, which takes three arguments, x y and value. Value is what is printed in a position on a grid, x & y are the coordinates.
self.listOfRows[x - 1][y - 1] = valueIndexError: list assignment index out of range
def gridMileage(List):
x = []
y = []
n = []
k = 0
best = 0
while len(List) > 0:
for i in range(len(List)):
x = List[i][0]
y = List[i][1]
n.append([x,y])
if x > best:
best = x
elif y > best:
best = y
newGrid = Grid(best)
while k < 2:
newGrid.setValue(n[k][0], n[k][1], List[k])
k = k + 1
del List[0]
del List[1]
del n[0]
del n[1]
newGrid.setValue(n[0], n[0] + 1, math.sqrt((n[0][0] - n[1][0])**2 + (n[0][1] - n[1][1])**2))
newGrid.setValue(n[1] + 1, n[1], math.sqrt((n[1][0] - n[0][0])**2 + (n[1][1] - n[0][1])**2))
z = len(newGrid.listOfRows)
while z > 0:
print(newGrid.listOfRows[z - 1])
z = z - 1
class Grid:
def __init__(self, n):
self.listOfRows = []
for i in range(n):
row = []
for j in range(n):
row.append('*')
self.listOfRows.append(row)
def setValue (self, x, y, value):
self.listOfRows[x - 1][y - 1] = value