我知道有很多这样的问题,但我看了之后,没能解决我的问题。我还在学习Python,所以可能会发生一个简单的混淆。在
到目前为止,误差是通过构造的for循环到达的。在
# down
column = 2
grid = [ 10, 10 ]
while range > 0:
# grab at the top
cur = genes[((grid[1] - 1) * grid[0]) + column]
prev = cur
for a in range((grid[1] - 2), -1, -1):
# start one below from the top
cur = genes[(a * grid[0]) + column]
genes[(a * grid[0]) + column] = prev
prev = cur
# now apply the change back to the top
genes[((grid[1] - 1) * grid[0]) + column] = prev
if get_fitness(genes, grid) > fitness:
print("After Down")
board = Board(genes, grid)
board.print()
print("-------------------")
return
range -= 1
按要求
^{pr2}$
您将
range
定义为数字但你后来把它当作一个函数
^{pr2}$将
range
整数重命名为其他值例如,可以执行向后For循环
相关问题 更多 >
编程相关推荐