def calculate_fitness(self): fitness = 0 for i in range(POPULATION_SIZE): gene = self.genes[i] # 判断树是否超出土地边界 if gene['x'] - TREE_RADIUS < 0 or gene['x'] + TREE_RADIUS > LAND_WIDTH or gene['y'] - TREE_RADIUS < 0 or \ gene['y'] + TREE_RADIUS > LAND_HEIGHT: continue怎么缩进
时间: 2023-06-14 20:06:02 浏览: 106
Calculate.rar_site:www.pudn.com
你可以用4个空格进行缩进,这是Python官方文档推荐的方法。例如:
```
def calculate_fitness(self):
fitness = 0
for i in range(POPULATION_SIZE):
gene = self.genes[i]
# 判断树是否超出土地边界
if gene['x'] - TREE_RADIUS < 0 or gene['x'] + TREE_RADIUS > LAND_WIDTH or gene['y'] - TREE_RADIUS < 0 or gene['y'] + TREE_RADIUS > LAND_HEIGHT:
continue
# 进一步计算fitness
# ...
# ...
```
注意缩进的空格数要保持一致,不要混用空格和Tab键。
阅读全文