tags:

views:

68

answers:

2

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",finish,"\n"
A: 

you are reassigning start and finish in your code (in the head of the code and in the ifs expressions.
As probably for some reason the if conditions result both False, start and finish are not reassigned and you get the first values given to these parameters: that is, the len of the data that probably is 7

joaquin
+2  A: 

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).

Alex Martelli
i just figured out that 7 is the # of lines in the txt files, how can i fix this ?
alberto
the txt files has 7 lines and 10 element in each lines.
alberto
You could try **using** that `data` list -- you never use it anywhere in your code (except for the two calls to `len` at the start), rather you're assigning an empty list to `pos` then "using" `pos` (which obviously does nothing). Whatever problem related to `data` you want to solve, how can you possibly even _dream_ of solving it while never, ever **using** what `data` contains?!
Alex Martelli
how can i make the changed?
alberto
@alberto, you can change your code with any text editor of your choice. Presumably you should change it to remove the silly assignment to `pos` and change all uses of `pos` into uses of `data`.
Alex Martelli
Oh, and, instead of the weird initialization of start and finish, just assign `None` to each of them at the start.
Alex Martelli