Build a Pin Extractor - Step 17

Tell us what’s happening:

I am almost at the final point and it does not pass . Monitor says my_poems is not defined. I have attempted to define it. Please suggest solution.

Your code so far


# User Editable Region

def pin_extractor(my_poems):
    all_codes = []
    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'
            all_codes.append(secret_code)
    return all_codes

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'
my_poems_list = [poem, poem2, poem3]
print(pin_extractor(my_poems))
# print(pin_extractor(poem))

# User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build a Pin Extractor - Step 17

You have changed or added to the code way more than was asked. You have also not changed the function argument as asked.

I suggest you reset the step and only change the function argument and add a for loop around the existing code inside the function.

I did reset . It asks for poem to be loop variable.” for poem in poems” does not do this? I have edited.

Update the function argument to be poems

Why did you update the argument to be “my_poems” and not “poems” ?

You just need to do exactly what the instructions say.

You need to understand how functions, parameters and arguments work. You can review that here:

https://www.w3schools.com/python/python_arguments.asp

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

all_codes.append(secret_code)

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’

my_poems = [poem, poem2, poem3]

print(pin_extractor(my_poems))

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

all_codes.append(secret_code)

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’

my_poems = [poem, poem2, poem3]

print(pin_extractor(my_poems))

I changed to poems, the issue now is putting everything under the initial for argument. lease help.

Why do you have so much code?

Reset the step, it should only be 21 lines of code.

What is this line?

Only do what the instructions ask, don’t do anything else.

  1. Reset the step.
  2. Update the function argument to be poems,
  3. then create a for loop around all the current content of the function that iterates over poems and uses poem as loop variable.

That’s all, nothing else. Don’t create any new variables like “my_poems” or “all_codes”. The instructions do not ask for that.

Just do what the instructions ask, nothing else.

Still having problems with “moving the body of the function”

I don’t see that in the instructions?

You’ve marked this as Solved, do you still need help?