Long-Range Division in the Forest, how do I calculate division?

Need help on Long-Range Division in the Forest.

It’s one where there are two rows of mines and you’re supposed to shout out ranges for a cannon to hit the mines.

I can’t figure out how to calculate the range to enemy using division. I understand the syntax is 4 / 2 == 2, but I can’t seem to do distanceToEnemy / 3 == …

Here’s the bare code of the episode:

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(“Fire!”)

Say second range: distanceToEnemy divided by 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.

I ended up sort of guessing, which misses the point. Anyone know how I should use Python to calculate the range?

Hello, I think you already calculated it using hero.distanceTo(enemy). As you stored it in the variable distanceToEnemy I think you could divide the range by using distanceToEnemy/ 3.

The forward slash is used to divide numbers in Python.

So it would look something like hero.say(distanceToEnemy/ 3)

or if you were to do it without storing the range finding method in a variable. Instead entering it directly, it might look like: hero.say(hero.distanceTo(enemy)/ 3).

I hope that helps. And apologize if any of the syntax is slightly off. I am new myself.

1 Like