As people have said before, format your code properly. I’ve done it for you this time, but do so yourself in the future.
I’ll go through your code step by step:
Line 3: You need to check for
enemy, since you already created a variable for
findNearestEnemy(). Also, if-statements require a colon after the statement is asked.
Line 5: You only need an
else, not an
if else. Again with the colon.
Overall comment: Your indentations are a little mixed up. You need to indent your code inside the loop all the same level, then indent one more for