Build a Pin Extractor - Step 19

Tell us what’s happening:

I am getting lost. The instructions are not clean. Can you pls help?

Your code so far

def pin_extractor(poem, poem2, poem3):
    secret_codes = []
    for poem in poem, poem2, poem3:
        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'
        secret_codes.append(secret_code)

# User Editable Region

    return secret_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'

print(pin_extractor([poem, poem2, poem3]))

# User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15

Challenge Information:

Build a Pin Extractor - Step 19

I am getting lost, the instructions are really enigmatic. My last code is

def pin_extractor(poems):
    secret_codes = []
    poems = [poem, poem2, poem3]
    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'
        secret_codes.append(secret_code)
    return secret_codes
print(pin_extractor([poem, poem2, poem3]))
poem = """Stars and the moon
shine in the sky
white and
until the end of the night"""

What do I do wrong? Please do not reply that I have to follow instructions, because I think the issue is that they are so unclear I am not sure what to do.

And in the console, the only comment I find is that poem is not defined. Really???

what do you not find clear of the instructions?

that happens if you use a variable before defining it

you are using poem on one line, but poem starts existing only on the line below

where are poem2 and poem3?

Obviously everything since it does not work. Pls tell me which part of the instruction I would not have followed properly.

you did many things extra which are causing issues

poem2 and poem3 do not exist anymore

you also have moved the function call, see this comment for more about that Build a Pin Extractor - Step 19 - #6 by ILM

OK, so i put the print function at the very end underneath the definitions of poem, poem2, poem3, then it tells me: “cannot access local variable ‘poem’ where it is not associated with a value”

Sorry, I am lost now. What do you mean with poem2, and poem3 do not exist anymore?

you posted code where poem2 and poem3 are not present, so I assumed they did not exist anymore

post the code please

My code below. all 3 poems are there

def pin_extractor(poems):
    secret_codes = []
    poems = [poem, poem2, poem3]
    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'
        secret_codes.append(secret_code)
        return secret_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'

print(pin_extractor([poem, poem2, poem3]))

why have you added this line?
note also that the return you have added is not in the right place, right now it’s inside the loop, meaning the loop will not loop all the times we want it to loop

reset the step, and do only the two things you are asked to do

  • add the return on the last line of the function
  • update the function call on the last line of the code

OK, so I reset, then return secret_code, uncomment, and update the argument for (poem, poem2, poem3), my code is below, but then I get the comment: You should have the function call print(pin_extractor([poem, poem2, poem3]))

def pin_extractor(poem, poem2, poem3):
    secret_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'
        secret_codes.append(secret_code)
    return secret_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'

it looks like you removed the function call that was present

and instead updated the function definition here:

please review the difference between function call and function definition

OK, got it, Thanks!!!

Try to rewrite the instructions as a series of steps.

For example,

Finally, return secret_codes, then uncomment the function call and update the argument to be [poem, poem2, poem3]. Now your function works with multiple poems at once, and can extract multiple pins!

  1. return secret_codes
  2. uncomment the function call
  3. update the argument to be [poem, poem2, poem3]

You did all three of these things. So, you DO actually understand the instructions perfectly. It was done.

Then, you changed the function parameters to require 3 arguments. That wasn’t in the instructions, so don’t do that.

It also does not make sense since you call the function with 1 argument, a list.

Then you rearranged the code and removed some variable declarations. Also, not in the instructions.

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