Computer science 5 Dangerous tracks need help

Hi everybody,
On Dangerous tracks from cloudrip mountain I tried the comments and hints but it didn’t help much.
Here is my code:


Most of the headhunters died but three of them didn’t. Why is this?

Sorry here it is with formatting:

# Protect the village with fire traps.
# Mine all passages in four directions.
# You have 80 seconds before the ogres attack.

# Build traps on the line y=114 from x=40 to x=112 with step=24.
def buildNorthLine():
    for x in range(40, 113, 16):
        hero.buildXY("fire-trap", x, 114)

# Build traps on the line x=140 from y=110 to y=38 with step=18.
def buildEastLine():
    # Complete this function:
    for y in range(110, 38, -16):
        hero.buildXY("fire-trap", 140, y)
    pass

# Build traps on the line y=22 from x=132 to x=32 with step=20.
def buildSouthLine():
    # Complete this function:
    for x in range(132, 32, -16):
        hero.buildXY("fire-trap", x, 22)
    pass

# Build traps on the line x=20 from y=28 to y=108 with step=16.
def buildWestLine():
    # Complete this function:
    for y in range(28, 118, 16):
        hero.buildXY("fire-trap", 20, y)
    pass

buildNorthLine()
buildEastLine()
buildSouthLine()
buildWestLine()
hero.moveXY(40, 94)

Exactly where is this level i cant find it

its in mountain(ugh why 20 chars)

The problem is the incorrect use of python range() function, see Python range() function
Step by step explanation: pythontutor
Animated Gif:

In this function and all the rest, you need to put in the correct step. Everything else is correct. It is a similar problem I faced too.

So will this be OK?

def buildNorthLine():
    for x in range(40, 113, 24):
        hero.buildXY("fire-trap", x, 114)
# Build traps on the line x=140 from y=110 to y=38 with step=18.
def buildEastLine():
    for y in range(110, 38, -18):
        hero.buildXY("fire-trap", 140, y)

“In this function and all the rest, you need to put in the correct step. Everything else is correct.”
If this is true where is the last fire-trap

fire-trap at x = 140  y = 38

1 Like

I did put the right steps but it was worse.

1 Like

I had the same problem. I couldn’t find the last fire-trap.

1 Like

I’m not sure what you mean.

1 Like

Actually this time two didn’t die.

1 Like

thanks. I just needed to add some code about the fire-traps and it worked. :grinning:

1 Like

If you did something like:

buildSouthLine()
hero.buildXY("fire-trap", 32, 22)

It’s clever, but you didn’t learn anything about python range() function

1 Like

P.S. I don’t know who granted me a Solution but the code in the second animated gif is intentionally WRONG!

2 Likes

Congratulations on succeeding :partying_face:! But @xython was right. You don’t learn anything if you add the code for the last two. I suggest doing trial and error to find the answer, the right answer, and not the answer where you don’t learn.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.