【发布时间】:2023-03-10 13:40:01
【问题描述】:
我有一个 10x10 的数组,我需要处理两点之间对角线上的所有点,并检查列表中是否存在。我这样做了,但我不知道为什么它不起作用:
把你放在上下文中:
a = [i,j] b = [i,j], i 和 j = range(11)
例如,下面的代码应该适用于 a = [5,4] b = [8,7]。
...
elif (b[1] - a[1]) == (b[0] - a[0]):
#to southeast, code for the other 3 cases are almost the same
if b[0] > a[0] and b[1] > a[1]:
n = a[0]
m = a[1]
while (n != b[0]) and (m != b[1]):
n +=1
m +=1
#don't think this part below is relevant
if board[n][m] in somelist:
mov_inv += 1
else:
mov_inv += 0
这是在一个函数内部,如果 mov_inv > 1 则返回 False,如果 mov_inv = 0 则返回 True,但它不是那样工作的。希望你明白我的意思。谢谢
【问题讨论】:
标签: arrays list python-3.x