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

Help with the level "zig zag and zoom" in the Desert World

#1

I am stuck in the level Zig Zag and Zoom, in the desert, and I just get stuck after the first zig-zag. I don’t understand what is wrong with my code so please help me understand what my error is so I will not make it again. =)

Escape from Death Valley!

Move by with a zigzag pattern using real modulo functions.

This function returns a value from 0 to 15:

def mod15(n):
while n >= 15:
n -= 15
return n

This function should return a value from 0 to 9:

def mod9(n):
# While n is greater or equal to 9, subtract 9 from n:
while n > 9:
n = n-9
return n

Don’t change the following code:

while True:
time = hero.time
if time < 30:
y = 10 + 3 * mod15(time)
else:
y = 20 + 3 * mod9(time)
x = 10 + time
hero.moveXY(x, y)

#2

Please format your code as it says in the faq (located in the task bar to the left of your profile in the top right corner)
Thanks,
:lion: :lion: :lion:

#4
1 Like
#5
# Escape from Death Valley!
# Move by with a zigzag pattern using real modulo functions.

# This function returns a value from 0 to 15:
def mod15(n):
    while n >= 15:
        n -= 15
    return n

# This function should return a value from 0 to 9:
def mod9(n):
    # While n is greater or equal to 9, subtract 9 from n:
    while n > 9:
        n = n-9
        return n

# Don't change the following code:
while True:
    time = hero.time
    if time < 30:
        y = 10 + 3 * mod15(time)
    else:
        y = 20 + 3 * mod9(time)
    x = 10 + time
    hero.moveXY(x, y)

#6

You’re supposed to be pretty much copying the first function(mod15), into the second function(mod9) but with nine instead of fifteen. I can see 3 differences between them, 2 of the them matter and the other one doesn’t.
:lion: :lion: :lion:

1 Like
#7

It works! thx! =D

Mod edit: It’s great that you fixed it and figured it out but please don’t post final solutions.