# Village warder problem

this is my code:

``````# This function attacks the nearest enemy.
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)

# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
# If an enemy exists:
if enemy:
# And if "cleave" is ready:
hero.cleave(enemy)
pass

# In your main loop, patrol, cleave, and attack.
while True:
# Move to the patrol point, cleave, and attack.
hero.moveXY(35, 34)
findAndCleaveEnemy()
findAndAttackEnemy()

# Move to the other point:
hero.moveXY(60,31)
# Use findAndCleaveEnemy function:
hero.findAndCleaveEnemy
# Use findAndAttackEnemy function:
hero.findAndAttackEnemy
enemy = hero.findNearestEnemy()
if enemy:
hero.cleave(enemy)
hero.attack(enemy)
else:
hero.attack(enemy)
``````

I don’t see any problem but it marks me incomplete.

I don’t think that is a defined method.

You don’t need that part.

These should just be the function names with parenthesis, since this is not a method of the hero.

``````findAndCleaveEnemy()
findAndAttackEnemy()
``````

it still does not work.

``````# This function attacks the nearest enemy.
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)

# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
# Find the nearest enemy:
enemy = hero.findNearestEnemy()
# If an enemy exists:
if enemy:
# And if "cleave" is ready:
# It's time to cleave!
hero.cleave(enemy)
# In your main loop, patrol, cleave, and attack.
while True:
# Move to the patrol point, cleave, and attack.
hero.moveXY(35, 34)
findAndCleaveEnemy()
findAndAttackEnemy()

# Move to the other point:
hero.moveXY(60, 31)
# Use findAndCleaveEnemy function:
hero.findAndCleaveEnemy
# Use findAndAttackEnemy function:
hero.findAndAttackEnemy
``````

I do not know what I’m doing wrong.

Can u send me the link to the level?

That should be:

``````    findAndCleaveEnemy()
# Use findAndAttackEnemy function:
findAndAttackEnemy()
``````

`findAndCleaveEnemy()` and `findAndAttackEnemy()` are not methods of the hero. They are functions that tell the hero what to do. Define a function, then execute the function. The function here tells the hero to cleave if the hero is ready. It also tells the hero to attack the enemy if there is an enemy. Instead of writing it out each time in the while true loop, you can define it as a function and execute the function.

@kelvintaph, Please refrain from posting solutions. It does not help the person learn or improve.