I'm trying to figure what the values of xcoord_orig
and ycoord_orig
are when the last conditional statement is true i.e. when board[xcoordT][ycoordT] == computer
. I feel that as I have it right now, I'm simply printing their values if the conditional statement is true. But what I really want are the values of xcoord_orig
and ycoord_orig
under the first loop at the point where the last conditional statement is true. I'm not sure if this is clear but I thought I would ask.
for num in range(8):
for i in range(len(valid_list)):
xcoord_orig = valid_list[i][0]
ycoord_orig = valid_list[i][1]
xcoord1 = valid_list[i][0] + num_list[num]
ycoord1 = valid_list[i][1] + num_list2[num]
if 0 <= xcoord1 <= 7 and 0 <= ycoord1 <= 7:
piece = board[xcoord1][ycoord1]
if piece == player:
move_list = []
for i in range(2,8):
xcoordT = xcoord_orig
ycoordT = ycoord_orig - i
print(xcoord_orig, ycoord_orig)
if board[xcoordT][ycoordT] == computer:
move_list.append([xcoordT, ycoordT])
print(xcoord_orig, ycoord_orig)
AJ.
28.3k19 gold badges88 silver badges98 bronze badges
-
So did you want the actual values in separate variables? I'm a bit confused mate.Vinay– Vinay2011年05月17日 21:49:59 +00:00Commented May 17, 2011 at 21:49
1 Answer 1
This
for i in range(len(valid_list)):
...
for i in range(2,8):
Is epic fail. It can't be correct.
answered May 17, 2011 at 22:20
-
you mean reusing i or something else?user637965– user6379652011年05月17日 22:46:40 +00:00Commented May 17, 2011 at 22:46
-
@seekingjannah: You can't reuse variables randomly. Variables have meaning which you should be able to state clearly, completely and precisely. And the meaning of a variable in a given scope cannot ever change.
i
can't mean two different things in the two loops. That's just impossible to make sense of.S.Lott– S.Lott2011年05月17日 22:49:20 +00:00Commented May 17, 2011 at 22:49 -
Thanks for pointing out the reusing variables error. I changed it but it still doesn't fix my problem :(. In fact, it doesn't seem to make any difference at all.user637965– user6379652011年05月17日 23:06:31 +00:00Commented May 17, 2011 at 23:06
-
1I'm not saying reusing variables is a smart idea, but since the inner
for
block doesn't reference the outer value ofi
, and there is no code in the outer block after the inner one, it doesn't matter in this case.lynn– lynn2014年08月08日 21:08:45 +00:00Commented Aug 8, 2014 at 21:08
lang-py