Build a Pin Extractor - Step 17

Tell us what’s happening:

At wit’s end what am I missing? Is the existing body of the function not in the for loop? I’ve reset this so many times and can’t figure it out. I’ve played with the indentation and still get the same error.

Error: You should move the existing body of the function into the new for loop.

Your code so far


# User Editable Region

def pin_extractor(poems):
    for poem in poems:
        secret_code = ''
        lines = poem.split('\n')
        for line_index, line in enumerate(lines):
            words = line.split()
        if len(words) > line_index:
            secret_code += str(len(words[line_index]))
        else:
            secret_code += '0'

    return secret_code

# User Editable Region

poem = """Stars and the moon
shine in the sky
white and
until the end of the night"""

poem2 = 'The grass is green\nhere and there\nhoping for rain\nbefore it turns yellow'
poem3 = 'There\nonce\nwas\na\ndragon'

# print(pin_extractor(poem))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Build a Pin Extractor - Step 17

is this inside the loop?

I believe so. I have tried all different ways of indenting it and still get the same error.

notice how the for and the return are on the same column, that means that the return is not inside the loop

Well, I indented it and still get the same error.

def pin_extractor(poems):
    for poem in poems:
        secret_code = ''
        lines = poem.split('\n')
        for line_index, line in enumerate(lines):
            words = line.split()
        if len(words) > line_index:
            secret_code += str(len(words[line_index]))
        else:
            secret_code += '0'
        return secret_code

If I indent it again or another time I still get the same error.

this is not correct, the loop on enumarate(lines) should have more things inside

if you can’t figure it out reset the step and try again

I’ve reset the step a million times. that line never changes and the instructions don’t say to change anything there. Do i go back a step? did i miss something?

what do you mean the line never changes?

starting code is

def pin_extractor(poem):

    secret_code = ''
    lines = poem.split('\n')
    for line_index, line in enumerate(lines):
        words = line.split()
        if len(words) > line_index:
            secret_code += str(len(words[line_index]))
        else:
            secret_code += '0'
    return secret_code

don’t you get this when you reset?

notice how there are things inside the loop, like the if/else

I understood I needed more code from your post. It turns out it was indentation. I went line by line and checked it until it worked. Thanks.

In the future, you can click the reset button to restore the original code.

image