Build a Pin Extractor - Step 17

Tell us what’s happening:

I copied the code from chatgpt and i putted it inside the for loop and i keep getting this message called “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:  # loop over each 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'  # add '0' for missing words

# User Editable Region

        # You can handle secret_code here for each poem

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pin Extractor - Step 17

Welcome to the forum @waleed2 !

You are missing some of the starting code that you were asked to move inside the for loop.

Please click the reset button to restore the original code and try again.

image

Happy coding!

I did try but it dosesnt work

Please post your updated code formatted as follows:

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

def pin_extractor(poems):  # now takes a list of poems
    for poem in poems:      # loop over each 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'
        # secret_code now holds the PIN for this poem

Tell us what’s happening:

I placed every block inside the for loop and also checked with chatgpt but it still showing me to put inside the new for loop i dont know what to do so please tell me whats wrong in this code

Your code so far


# User Editable Region

def pin_extractor(poems):  # parameter is now a list of poems
    for poem in poems:      # loop over each 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]))

# User Editable Region

            else:
                secret_code += '0'
        # secret_code now holds the PIN for this poem

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pin Extractor - Step 17

Tell us what’s happening:

I copied the code from chatgpt and i putted it inside the for loop and i keep getting this message called “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:  # loop over each 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'  # add '0' for missing words

# User Editable Region

        # You can handle secret_code here for each poem

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pin Extractor - Step 17

its fixed now i found the answer

Hi @waleed2,

You are missing the return for secret_code. That’s all! Just make sure it has the correct indentation so it lines up with where it should be sent back.

Welcome to the forum @waleed2

I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates.

Happy coding

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