# Sand shakes python

**URL:** <https://discourse.codecombat.com/t/sand-shakes-python/6086>\
**Category:** Uncategorized\
**Created:** [December 14, 2015, 6:01pm UTC](https://discourse.codecombat.com/t/sand-shakes-python/6086 "2015-12-14T18:01:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lundor5](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lundor5](https://discourse.codecombat.com/u/lundor5)\
**Post date:** [December 14, 2015, 6:01pm UTC](https://discourse.codecombat.com/t/sand-shakes-python/6086/1 "2015-12-14T18:01:28Z")

</div>

My hero just runs into the mines

```python

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)
```

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [December 15, 2015, 5:17am UTC](https://discourse.codecombat.com/t/sand-shakes-python/6086/2 "2015-12-15T05:17:27Z")

</div>

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