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

Don't Rush Be Quiet

This is my code. Can someone help? I don’t know what is wrong with my code. My hero gets all gems, but dies shortly after.

def mod30(n):
if n >= 30:
return n - 30
else:
return n

def mod40(n):
# Use an if-statement to return the correct value.
item = hero.findNearestItem()
hero.moveXY(item.pos.x, item.pos.y)
hero.shield()
hero.shield()

return n

while True:
item = hero.findNearestItem()
items = hero.findItems()

time = hero.now()
x = mod30(time) + 25
y = mod40(time) + 10
hero.moveXY(item.pos.x, item.pos.y)

Thank You

1 Like

Function mod40(n) should return a value from 0 to 40.

1 Like

Can you explain that? I just started and I have no idea what that means. No offense.

1 Like

I explain it for Function mod30(n) ( should return a value from 0 to 30).

def mod30(n):
    if n >= 30:
         return n - 30
    else:
        return n

n=5 => else=> return 5
n=30=>else=> return 30
n=50=>if n>=30=> return 50-30 => return 20

return value is from 0 to 30 …

1 Like

Oh! Thanks! I understand now.

1 Like

I tried and it didn’t work. Thanks, though.

2 Likes

I have the same problem. this is my code:

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

help!!! :frowning:

Hi @Xuan.
I think you might be overthinking this level.
The mod40() function should be exactly the same as the mod30 function but with 40 instead of 30.
They should be the same, because they both do the same thing:

# This function returns a value from 0 to 30 (0 <= n < 30)
--
# This function should return a value from 0 to 40 (0 <= n < 40)

They should be the same.
I hope this helps.
:lion: :lion: :lion:

I did this:

if n <= 40:
        return n + 40
        else:
            return n

It didn’t work.
(By the way, I’m Xuan’s son.)

It said the X thing.

Actually, I tried again ( Reloaded it and it worked but it killed me at the end.
I don’t know if this is different but I did this:

def mod40(n):
    # Use an if-statement to return the correct value.
    if mod40 <= 40:
        return n + 40
    else:
        return n

Hi Xuan('s son), the mod30 and mod40 functions are still different:

There’s still one tiny difference, once you’ve fixed it your code should work.
:lion: :lion: :lion:

Thank you. I’m on cubic minefield now.