finding a solution to a giving maze txt.file
how can i fix this program, the problem is when it print out the coordinate it give me a 7 for the start and finish, i would appreciated you help, thanks
start = (len(data))
finish = (len(data))
pos= []
for i in range(len(pos)):
for j in range(len(pos[i])):
if pos[i][j] == "S":
start=(i,j)
elif pos[i][j] == "F":
finish=(i,j)
print "S found in",start,
print "\nF found in",fin开发者_JAVA百科ish,"\n"
Look at the start of your code:
start = (len(data))
finish = (len(data))
pos= []
for i in range(len(pos)):
len(pos)
is zero, of course (you've just assigned the empty list to pos
, so what else could that length possibly be but 0?!), so the loop executes zero times, start
and finish
never change, and what you print for them after the loop is exactly what you assigned to them here -- and despite all the redundant parentheses that's just the same integer for both (which you tell us is 7
, so presumably whatever data
is, it has a length of 7).
精彩评论