Think Ahead level unexpected token (what does that mean?)(SOLVED)

hi I’m trying to do Think Ahead level and am getting this error when trying to debug why the soldiers are getting blown up.

Here is my current code. Any Ideas what this error means?

# You need to distract "Big Bertha" until you special squad arrives.
# The cannon shoots at the pair of soldiers closest to each other.

# This function finds the pair of units
# with the minimum distance between them.
def findNearestPair(units):
    minDistance = 9001
    nearestPair = ["Nobody", "Nobody"]
    # You need to check and compare all pairs of units.
    # Iterate all units with indexes "i" from 0 to "len(units)".
    for i in range(0,len(units)):
        # Iterate all units again with indexes "j".
        for j in range(0,len(units)):
            # If "i" is equal to "j", then skip (continue).
            if i==j:
                continue
            # Find the distance between the i-th and j-th units.
            distance=units[i].distanceTo(units[j])
        `   if i==1 and j==2:
                hero.say(i+','+j+' '+distance)
            # If the distance less than 'minDistance':
            if distance<minDistance:
                # Reassign 'minDistance' with the new distance.
                minDistance=distance
                # Reassign 'nearestPair' to the id's
                # of the current pair of units.
                nearestPair=[i,j]
    return nearestPair


while True:
    soldiers = hero.findByType("soldier")
    # We know when the cannon shoots.
    if hero.time % 8 == 5:
        # Find which pair of soldiers in danger and protect them.
        pairOfNames = findNearestPair(soldiers)
        # Say the soldier's names and wizards will protect them.
        hero.say(pairOfNames[0] + " " + pairOfNames[1])

do:


def findNearestPair(units):
    # These variables are used to store comparable value and results.
    minDistance = 9001
    nearestPair = ["Nobody", "Nobody"]
    # You need to check and compare all pairs of units.
    # Iterate all units with indexes 'i' from 0 to 'len(units)-1'.
    for i in range(0, len(units)):
        for j in range(i + 1, len(units)):
            # Use an additional loop through indexes 'j' from 'i+1' to 'len(units)'.

            # Find the distance between the i-th and j-th units.
            distance = units[i].distanceTo(units[j])
            # If the distance less than 'minDistance':
            if distance < minDistance:
                # Reassign 'minDistance' with the new distance.
                minDistance = distance
                # Reassign 'nearestPair' to the names of the current pair of units.
                nearestPair = [units[i].id, units[j].id]
    return nearestPair

while True:
    soldiers = hero.findByType("soldier")
    # We know when the cannon shoots.
    if hero.time % 8 == 5:
        

        pairOfNames = findNearestPair(soldiers)
        # Say the soldier's names and wizards will protect them.
        hero.say(pairOfNames[0] + " " + pairOfNames[1])

1 Like

Thanks for that. I was really trying to work out what the issue was that generated the error though.

I found the problem which was a rogue apostrophe, which I thought was a bit of dirt on my screen.

2 Likes

ummmm 1 why (respectivly) give the solution to your self when I solved it 2 please wright (solved)

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.