2 回答

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
做這樣的事情。兩個(gè) for 循環(huán)分別從x_lowtox_high和y_lowto迭代y_high
#Limits for iterating through the grid
x_low = -200
x_high = 201
y_low = -200
y_high = 201
#List to append your coordinates to, if condition is true
coords = []
for xval in range(x_low, x_high):
for yval in range(y_low, y_high):
if condition:
coords.append((xval,yval))

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
您對(duì)x和y變量的使用有點(diǎn)多余。您可以簡單地更改迭代的起點(diǎn),并擁有xval并yval表示您當(dāng)前的坐標(biāo)。
for xval in range(-200, 201):
for yval in range(-200, 201):
# xval and yval now represent your current x coordinate and y coordinate
在range(start, end)函數(shù)的這種用法中,您指定起點(diǎn)和終點(diǎn),然后從[start, ..., end)
添加回答
舉報(bào)