如何简化这个 if 语句?它是一个加号: http://i.stack.imgur.com/PtHO1.png
如果语句完成,则在 x 和 y 坐标处设置一个 block 。
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if (x%5 == 2 or x%5 == 3 or x%5 == 4) and \
(y%5 == 2 or y%5 == 3 or y%5 == 4) and \
not(x%5 == 2 and y%5 == 2) and \
not(x%5 == 4 and y%5 == 2) and \
not(x%5 == 2 and y%5 == 4) and \
not(x%5 == 4 and y%5 == 4):
...
最佳答案
这是一样的:
if (x % 5 == 3 and y % 5 > 1) or (y % 5 == 3 and x % 5 > 1):
关于python - 如何简化这个很长的 if 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4088145/