This code is correct according to your rules. And I can not pass that level as can not many others.
If you wish that I woud pay you money, you must do much better than that! Please remove the bug or correct my code. The first time when I ran this code it worked well, then I submitted and it failed like for many others
# This shows how to define a function called cleaveWhenClose # The function defines a parameter called target def cleaveWhenClose(target): if hero.distanceTo(target) < 5: pass # Put your attack code here # If cleave is ready, then cleave target ready = hero.isReady("cleave") hero.cleave(target) # else, just attack target! else: hero.attack(target) # This code is not part of the function. while True: enemy = hero.findNearestEnemy() if enemy: # Note that inside cleaveWhenClose, we refer to the enemy as target. cleaveWhenClose(enemy)