Sand shakes python

My hero just runs into the mines


loop:
    coins = self.findItems()
    coinIndex = 0
    nearest = None
    nearestDistance = 9999
    
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
        distance = self.distanceTo(coin)
 
    if distance < nearestDistance:
        nearest = coin
        nearestDistance = distance
    if nearest:
        self.moveXY(nearest.pos.x, nearest.pos.y)

Place the part where you determine the nearest coin inside the while – loop.