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

Friend and Foe (Python){SOLVED}

#1

I keep trying to complete the level “Friend and Foe” in the level python.
I can’t seem to get it . . . .
19%20AM

What do I add next to complete the level?

#2

All you have to do is duplicate what you’ve done for friend with enemy.

#3

Oh, Thank You so much! But I tried that and it did not work.

#4

post your code and we’ll look at it to find the issue.

#5

the code is the one on the top

#6

If so, then you’ve not written anything for the enemy portion. The directions state:

# Now find the nearest enemy and tell them to go away.
#7

so am i supposed to do this?
17%20PM

#8

Do it just like the above that you did for friend. Define it, then an if conditional statement, then tell the enemy what to do with a concatenated hero.say statement. What you’ve done so far is exactly what you need to do with enemy.

#9

can you elaborate on that please!:sweat_smile:

#10

Just follow the format that you see for friend. Do exactly the same thing but use enemy as the variable instead of friend and in the hero.say statement, do as the instructional comments say and tell the ogres/munchkins to go away instead of saying, “To battle”.

#11

one more question, “Sorry!”
um what am I supposed to say to the enemies?

#12

The specific phrase doesn’t matter. Just say something telling them to go away and concatenate it with the enemy.id just like you did with the friends.

#13

I tried but this is what showed.

#14

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

#15

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

#16

Use enemy = hero.findNearestEnemy before

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

It should look like this:

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

sorry, i tried it is not working

#18

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

#19

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

#22

Post your code so we can see what is wrong.

1 Like