I just wanted to remind new users, not to pick on you, to post your code with radiant and harmonious formatting as quoted in the FAQ.
Post your code with radiant, harmonious formatting
You can get your code to format properly by surrounding it in triple backticks. This:
enemy = self.findNearestEnemy()
enemy = self.findNearestEnemy() if enemy: self.attack(enemy)
You should receive, after you have created your account, an message from @schmatz, the community guidelines.
Please this post if you find it useful or helpful