Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Friend and Foe (Python)

You have to define enemy; enemy = hero.findNearestEnemy.

Um . . . .
(I know that I put two equal signs but thats what it said to do)

Use enemy = hero.findNearestEnemy before

if enemy: 
    hero.say("Go away, " + + "!")

It should look like this:

enemy = hero.findNearestEnemy
if enemy: 
    hero.say("Go away, " + + "!")

sorry, i tried it is not working

Please post your code so I can see what you did wrong!

just with parenthesis right after the word, findNearestEnemy don’t just copy and paste or something and try.

Post your code so we can see what is wrong.

1 Like

@Saanvi_Mysore already did.

it aint working

I’m not sure if this is a problem, but you seem to be using two different coding languages at the same time.

ok i got it

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

are you telling me


I think @Tripp sent that on accident

Which language do you want to use? By the image you’re providing us, you’re simultaneously trying to use Python and Javascript, but the current language you are using in that level is Python. Press the :arrows_counterclockwise: Restart button and do the level in Python. If you want to switch to JavaScript, press Game Menu-> Change Language/Hero, then select Javascript or any other language.

Note: If you changed your language, be sure to press :arrows_counterclockwise: Restart after loading the level.

what does it mean by rallying the troops is it attacking or rallying plz help

while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + + “!”)
# Now find the nearest enemy and tell them to go away.
enemy = hero.findNearestEnemy()
if enemy:
hero.say(“go away”)

Don’t forget to call the enemy by name like you did with your friends.

1 Like

what do you mean name enemy

what does it mean by rally the troops

If you look at what you said to your friends:

hero.say("To battle, " + + “!”)

You said something other than just a message. How do you think you could change this:

hero.say(“go away”)


Hope you solve this level.
:lion: :lion: :lion:

1 Like