Don't Rush Be Quiet help

I don’t understand. To me the code makes perfect sense.

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)


1 Like

Are you sure all your indentations are correct? :wink:

Yes, what about this.

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)


2 Likes

Did you put anything in the mod40(n) function? It looks empty to me. :slight_smile:

1 Like

this one doesn’t work, what am I doing wrong??

# 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 0 <= n < 40:
        return n

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

The sample code for mod30 function tells you how to write the function for the mod40 function. Just follow the format except write a 40 instead of a 30. It’s literally the same function.