Zig zag and zoom help

# 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:
        9-n
    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)

This is my code for zig zag and zoom. But something keeps happening and the the third zig zag always fails and my hero gets stuck HELP!

2 Likes

Please format your code with triple backticks ( ` ) above and below your code.

3 Likes

The code: 9 - n is only a statement and does nothing. Make sure you assign it to variable n. Review what the sample code did for mod15, specifically, look at the -=.

1 Like

Please don’t post finished solutions. This board isn’t here to provide solutions just so that people can move on to the next level. It’s here to help people find the solutions so that when they move to the next level, they know how to find the solution on their own. You can’t learn to code if you don’t learn how to figure things out. Being given solutions is counter-productive to this goal. Please delete your post. Thanks.