Don't rush, be quiet plz help [solved]

this is my code:

# Watch out, cannons are ready to fire!
# Move slow along a special pattern to confuse them.

# This function returns a value from 0 to 30 (0 <= n < 30)
def mod30(n):
    if n >= 30:
        return n - 30
    else:
        return n

# This function should return a value from 0 to 40 (0 <= n < 40)
def mod40(n):
    # Use an if-statement to return the correct value.
    if n >= 40:
        return n

# You don't need to change the following code:
while True:
    time = hero.time
    x = mod30(time) + 25
    y = mod40(time) + 10
    hero.moveXY(x, y)

I keep getting this error:Screenshot (21)

you forgot to add else: return n

add -40 on the end of the n

I’m still confused why I keep getting the error

for mod 40 just do the same thing as mod 30 just that its - 40

I tried that but it keeps giving me the error about y being NaN.

Please post your new code after every change so we can see if you’ve made the correct change to it.
Danny

# Dodge the cannons and collect 8 gems.
# Watch out, cannons are ready to fire!
# Move slow along a special pattern to confuse them.

# This function returns a value from 0 to 30 (0 <= n < 30)
def mod30(n):
    if n >= 30:
        return n - 30
    else:
        return n 

# This function should return a value from 0 to 40 (0 <= n < 40)
def mod40(n):
    # Use an if-statement to return the correct value.
    if n >= 40:
        
        return n - 40

# You don't need to change the following code:
while True:
    time = hero.time
    x = mod30(time) + 25
    y = mod40(time) + 10
    hero.moveXY(x, y)

cough cough.
This level is not as hard as you may think it is. Look at the top function, then literally copy it onto the bottom one, but use 40 instead of 30. They should do the same thing.
Danny

why did you wright cough cough?

Thanks although idk how the error was solved

Just because maybe @qwerty had not quite correctly read your post, so I was bringing it up again for him to see (because you’re right in what you said, I just repeated it).

The reason y was NaN (which means nothing) was because you didn’t return a value in your function. Now you’ve checked if n > 40 and < 40 so it will always return a value.
Danny

okay thanks 20000000

1 Like

ok I understand thanks for explaining @Deadpool198

1 Like

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