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

Count Emptiness Help [SOLVED]

# Solve the riddler puzzle and find the treasure.
# Count the whitespace on both sides of a riddle.

# This function moves the hero N steps right.
def moveNSteps(n):
    hero.moveXY(hero.pos.x + 8 * n, hero.pos.y)

# Read the riddle.
riddle = hero.findNearestEnemy().riddle
# Trim whitespace from both sides and store in a variable
trimmed = riddle.trim()
# Find the difference between the `riddle` and `trimmed` lengths:

# Use the result and moveNSteps function to move to the spot:
# Say something there!
hero.say("somethings there!")

type or paste code here

can anyone tell me what find the difference between the riddle and trimmed lengths means?

Think about a string as a literal collection of characters. A space at the beginning or end, aka whitespace, also counts as a character. So

test1 = "..this is a test.." # pretend the dots are just spaces.
test2 = "this is a test"

len1 = len(test1) # which comes out to a length of 18 characters
len2 = len(test2) # which comes out to a length of 14

test3 = test2.trim
len3 = len(test3) # which comes out to a length of 14

So, that is telling you to subtract the two items and use the difference to move that many steps. In your code, ‘riddle’ is the original text. ‘trimmed’ is after it is cleaned up…trimmed. Take the difference between the two, and pass that as the ‘n’ variable to your function.

that you so much that was really helpful