Sand Snakes Bug

# This field is covered in firetraps.  Thankfully we've sent a scout ahead to find a path.  He left coins along the path so that if we always stick to the nearest coin, we'll avoid the traps.

# This canyon seems to interfere with your findNearest glasses!
# You'll need to find the nearest coins on your own.
while True:
    coins = hero.findItems()
    coinIndex = 0
    nearest = None
    nearestDistance = 9999
    
    # Loop through all the coins to find the nearest one.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
        distance = hero.distanceTo(coin)
        # If this coin's distance is less than the nearestDistance
        if distance < nearestDistance:
            # Set nearest to coin
            nearest = coin
            # Set nearestDistance to distance
            nearsetDistance = distance / 2
            
    # If there's a nearest coin, "_" to its position. You'll need "_" so you don't cut corners and hit a trap.
    if nearest:
       (nearest.pos.x, nearest.pos.y)  # –trying not to give the answer

I believe my code is correct, but my hero dies every time. My friend have the exact problem on sand snakes yesterday. This happened two times. Even though he restarted it and he retyped the code and it worked(and I can do the same), can you guys please fix the bug so that it won’t happen to other people. Thank You

Sorry Code_Master, it’s not a bug…your code logic is a bit off.

  1. Why are you dividing distance by 2?
  2. You don’t really need that final if statement…instead, try replacing it with your move statement.
  3. Thank you for preserving the answer! :slight_smile:

<Moving this topic to Level Help, rather than Bugs.>

  1. because I am trying not to give the answer
  2. I tried, it didn’t work
  3. you are welcome
1 Like

Spelling most certainly does count! Line 21, in your original posted code…