0
question python question print number of list
list=[] position = (3,3) direction = [[0, 1]] for x, y in direction: if x >= 0 and x <= 7 and y >= 0 and y <=7: list.append((position[0] + x, position[1] + y)) y += y list.append((position[1] + x, position[1] + y)) y += y list.append((position[1] + x, position[1] + y)) x += x y += y print(list) I wan to print list of [[3, 4],[[3, 5],[[3, 6],[[3, 7]] but the code print [[3, 4],[[3, 5],[[3, 7]] I dont know why
3 Answers
0
Hope this helps
https://code.sololearn.com/cMCbOHDRpELR/?ref=app
0
1) You have appended something three times to the empty list, so there are 3 elements in list, not 4
2) Every time you doubled y, so y was: 1, 2, 4. You should use 'y += 1' to get 1, 2, 3 values.
0
l = []
position = (3,3)
direction = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]
for x, y in direction :
if 0 <= x <= 7 and 0 <= y <= 7:
l.append([position[0] + x, position[1] + y])
y += 1
l.append([position[1] + x, position[1] + y])
y += 1
l.append([position[1] + x, position[1] + y])
y += 1
l.append([position[1] + x, position[1] + y])
print(l)
I want the code print all diretion until 7 of direction = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]
but he print me th wrong position for example (3,3) with [[0, 1], is (3.4)