Build a Pin Extractor - Step 17

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

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 line_index < len(words):
                secret_code += str(len(words[line_index]))
            else:
                secret_code += '0'
        return secret_code

poem1 = """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'

poems = [poem1, poem2, poem3]

pin_extractor(poems)

Welcome to the forum @PrincetonAfeez !

Please post a link to the challenge and say, in your own words, what the issue is.

Happy coding!

link: https://www.freecodecamp.org/learn/python-v9/workshop-pin-extractor/step-17

I keep getting the same error:
You should move the existing body of the function into the new for loop.

It looks like you may have changed the starting code in areas you were not asked to change, which will cause the tests to fail. Please click the reset button to restore the original code and try again.

image

Thank you.

I kept trying different things. After resetting, I added the for loop and adjusted indentation. It worked

Thanks again, saved me from my frustration boiling over

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