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

[SOLVED] I need help with Friend and Foe can someone help plz?

this is my code:

while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + friend.id + “!”)
# Now find the nearest enemy and tell them to go away.
hero.findNearestEnemy()
hero.say(“go away”)
enemy = hero.findNearestEnemy()
if enemy:
can someone tell me what to put after the if enemy: part plz im stuck

Can you format your code as it is described here so we will be able to help you?

Andrei

# Peasants and peons are gathering in the forest.
# Command the peasants to battle and the peons to go away!

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

You can delete that.

In this if try to say enemy.id to go away with this model and put the ! at the end.

Andrei

1 Like

I will give you a example to understand better:
If enemy.id is “Aina”, then the hero should say this: Go away, Aina!. Do you understand?

Andrei

okay thank you i get it now.

1 Like

So have you finished this level?

Andrei

yes i have thank you for the help!

No problem! And congratulations for completing the level! :partying_face:

Andrei