[SOLVED]Long range division-Python-Help

I’m stuck… Anyone can help me ? Thank you.

# Destroy the mines!
# Use say to call out the range to the mines.
# Use division to calculate the range.

enemy = hero.findNearestEnemy()
distanceToEnemy = hero.distanceTo(enemy)

# Say first Range: distanceToEnemy divided by 3
hero.say(distanceToEnemy / 3)
hero.say("Fire!")
# Say second range: distanceToEnemy divided by 1.5
hero.say(distanceToEnemy / 1.5)
hero.say("Fire!")

# Say these things for motivation. Really. Trust us.
hero.say("Woo hoo!")
hero.say("Here we go!")
hero.say("Charge!!")

# Now, use a while-true loop to attack the enemies.
while True:
    enemy = hero.findNearestEnemy()
    if enemy :
        hero.attack(enemy)
1 Like

What happens when you run the code? Are you getting an error message? What does your hero do?

Please post a screen shot of your equipment. This may be a gear issue.

My hero can’t defeat the ogres. Thank you.


This is an equipment/gear issue. That wand isn’t inflicting much damage. It only inflicts 2.5 damage with each strike. Those two ogres have a combined total of 150 health. That means, with that wand, you would have to hit the two of them with 60 fire balls (30 a piece). You simply don’t have the time for that.

Either get a much better wand or just use a hero with a good sword. Your code is fine.

Just sloved! Thank you so much~ :smile:

Hi there, the code should have worked. Are you using a ranged weapon? The important note is that the while true loop required enemy = hero.findNearestEnemy() or it will only fight one ogre and not the other and it does not find the other one within the loop.

Hello and welcome to codecombat discourse, @Mark_Long! 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!

Hello! A few quick rules, please don’t revive dead topics. If you need help on this exact level then you can revive the topic. However, you are trying to help a person from three years ago (who passed this level already). That’s it, and have a great time on the forum!

1 Like