HELP PLEASE - УДАРЬ И ЗАМРИ уровень

Could you help me write the last lines, and tell me if I have errors in the code itself. I do not quite understand what I need to write in the last lines where it says "If the result is true incanAttack, then attack! "


def inAttackRange(enemy):
distance = hero.distanceTo(enemy)
# Почти все мечи имеют радиус поражения 3
if distance <= 3:
    return True
else:
    return False

Бей огров только когда они рядом.
while True:
# Найди ближайшего противника и сохрани его в переменную.
    enemy = hero.findNearestEnemy()
# Вызови функцию inAttackRange(enemy)с врагом в качестве аргумента.
# и сохрани результат в переменную canAttack.
    canAttack = inAttackRange(enemy)
# Если сохранённый в canAttack результат True, то атакуй!

Please learn to post your code properly.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.

see if the condition canAttack is True, and if it is, then attack.

(Final solution removed. Please don’t post completed code. Thanks.)

If you don’t complete this level, you can use this code. But i recommended you learn and understand yourself.

1 Like

I would normally say to not show code but in this case i’ll make an exception

Please don’t post the code.

And I forgot to say, if they’re crazy trying to figure out the code but even after a long time and a bunch of help, rather DM it than posting it where everyone could see it.