Tell us what’s happening:
You should move the existing body of the function into the new for loop. i’m getting this error could anyone can help me in this
Your code so far
# User Editable Region
def pin_extractor(poems):
results = []
# Loop over each poem
for poem in poems:
secret_code = ''
lines = poem.split('\n')
# Loop over each line
for i, line in enumerate(lines):
words = line.split() # split line into words
if words and i < len(words):
secret_code += str(len(words[i])) # take length of the i-th word
else:
secret_code += '0' # fallback if line empty or index too high
results.append(secret_code)
return results
# Poems
poem1 = """Stars and the moon
shine in the sky
white and
until the end of the night"""
poem2 = """The grass is green
here and there
hoping for rain
before it turns yellow"""
all_poems = [poem1, poem2]
# Run function
print(pin_extractor(all_poems))
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Challenge Information:
Build a Pin Extractor - Step 17