# Help me on this level please

this level is distraction maneuver.
I can’t find what is wrong
can you help me.
thanks a lot.

def findFurthest(units):
furthestUnit = None
maxDistance = 0
def findFurthest(units):
furthestUnit = None
maxDistance = 0
unitIndex = 0
while unitIndex < len(units):
target = hero.findNearestEnemy()
currentUnit = units[unitIndex]
# Find the distance to currentUnit:
distance = hero.distanceTo(target)
# If that distance greater than maxDistance:
if distance > maxDistance:
# Reassign furthestUnit and maxDistance:
maxDistance = distance
farthest = target
unitIndex += 1
return furthestUnit

# It’s like findNearestEnemy but vice versus.

def findFurthestEnemy():
enemies = hero.findEnemies()
furthestEnemy = findFurthest(enemies)
# Return furthestEnemy:
return futhestUnit

# The function makes the hero attack without distractions.

def attackWhileAlive(target):

``````# Attack target while it's health > 0:
while target.health > 0:
hero.attack(enemies)
pass
``````

while True:
# To protect peasants, hunt for furthest ogres.
furthestOgre = findFurthestEnemy()
if furthestOgre:
attackWhileAlive(furthestOgre)

1 Like

-Does the level display any error messages (for example "`thang` is undefined", etc.), or is your code just not beating the level?
Be sure to define `furthestUnit`. You are defining it as `farthest`, so that causes an error.
You define `currentUnit = units[unitIndex]`, but you do not use the variable `currentUnit` and instead use `target`. `target` is an undefined variable, which also causes an error.