Title: Step 17 – “move existing body into for loop” keeps failing
I’m stuck on Step 17 of the Pin Extractor workshop.
Instruction: move the existing body of the function into the new for loop.
I’ve tried returning a list, using results.append(), and removing print. Still fails. What does the test expect?
Thanks.
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 line_index < len(words):
secret_code += str(len(words[line_index]))
else:
secret_code += '0'
# User Editable Region
print(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'
poems = [poem, poem2, poem3]
pin_extractor(poems)
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Please reset the step using the circular arrow button, all the lines that are inside teh function need to be unchanged, and moved inside the loop exactly as they are
that includes keeping the return and moving it inside the loop
I’m having a similar experience. I tried refactoring by placing the existing function body inside the new for loop, but the tests are still not passing. It seems I’m missing a specific requirement. Could you help me understand the expected structure for this task?
I will happy to! make sure to create your own topic with your code!
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.
The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.