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
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
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
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
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.