I've been stuck on this level, stillness in motion, for ages. i need a big help

loop:
flag=self.findFlag(“green”)
if flag:
self.pickUpFlag(flag)
else:
enemy = self.findNearestEnemy()

If there is an enemy, then…

if enemy:

# If the enemy is less than 5 meters away, then attack()
distance = self.distanceTo(enemy)
if distance < 5:
    if self.isReady("cleave"):
        self.cleave(enemy)
    else:
        self.attack(enemy)

else:
# Otherwise (the enemy is far away), then shield()
pass
self.shield()

# Otherwise (there is no enemy...)
if enemy:
    # then move back to the X
    self.moveXY(40, 34)

i have no clue whats wrong with it
all it does is nothing

# Otherwise (there is no enemy...) why did you put if enemy: underneath # Otherwise (there is no enemy...)?