Value for love_maybe_lines_stripped did not match the expected value

I get the feeling I’m close with this code, for the first part of this exercise, but I get the dreaded " Value for love_maybe_lines_stripped did not match the expected value." error. Can anyone tell me why this doesn’t work?

I really want to stop looking at the answers and try to figure this out myself (with a little help from you fine people) :slight_smile:

love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ','\n' ,'   to conquer me home.    ']

love_maybe_lines_stripped = []
def strip_the_poem(love_maybe_lines):
  for line in love_maybe_lines:
    love_maybe_lines_stripped.append(line.strip())
  print(love_maybe_lines_stripped)

what happens when you return instead of print?

I get the same error. Not sure why, as “return” was my first instinct, too.

Let’s write a generic function…

def strip_the_poem(lines):
  y = []
  for line in lines:
    y.append(line.strip())
  return y

We call it with,

print(strip_the_poem(love_maybe_lines))

Notice that y is defined inside the function.

Okay, what you’re saying makes sense. Now I did this, and it’s saying " Could not find love_maybe_lines_stripped ." which I really don’t understand:

def strip_the_poem(love_maybe_lines):
  love_maybe_lines_stripped = []
  for line in love_maybe_lines:
      love_maybe_lines_stripped.append(line.strip())
  return love_maybe_lines_stripped

I’m not actually calling the function yet, because there is one more small part to the exercise after this, and I don’t think we’re supposed to call it yet.

The call will come, if even only on testing. Still, consider the generic approach that uses symbols in place of verbose names. I can debug my code; can you debug yours?

I’m sorry, I don’t understand what you’re asking. I did try using generic names, but then the CodeAcademy platform gives me a different error message.

I finally gave up and looked at the answer, and it looks like they didn’t even use a function to do this in their solution. But I still don’t get where I went wrong in my code, because it seems like it should have worked. I tried defining it with the empty list OUTSIDE the function, and inside. I tried it with both PRINT and RETURN. Nothing worked.

I guess I don’t understand how to debug. We haven’t used the “console” command yet, so I didn’t get that part of what you said, above.

I feel like I am never going to be able to understand this.

I do appreciate you trying to help, though.

and never will. It’s from a completely different scripting language, JavaScript. My bad. I’ve edited it to use print().

Ahh, okay. I’ll take another run at this one tomorrow. I really do appreciate your insight and your answers here in the forums.

Usually when you’re asked to set a variable, you should be setting it in your module (your file)

The function strip_the_poem looked fine to me. The only thing I could think might be causing the issue is the name of your argument you are passing to the function “love_maybe_lines”.

In the lesson this is the name of the list variable. If you use a general name for the argument like “poem” and change the references in the function from love_maybe_lines to poem. After when you call the function call it with the variable “love_maybe_lines”.

Not sure if this would help but if someone has more input the discussions are helping me learn.

love_maybe_lines = ['Always ‘, ’ in the middle of our bloodiest battles ‘, ‘you lay down your arms’, ’ like flowering mines ‘,’\n’ ,’ to conquer me home. ']

def strip_the_poem(poem):
love_maybe_lines_stripped =
for line in poem:
love_maybe_lines_stripped.append(line.strip())
return love_maybe_lines_stripped

print(strip_the_poem(love_maybe_lines)

Be a little careful checking the date when responding to queries. The post you’re replying to was from Nov2019 so it’s probably not going to help much.

I think the original issue was that the requirements didn’t ask for love_maybe_lines_stripped to be printed, it asked it to be saved as a list. Editing the function to call return was a step in the right driection but unless that function was actually called and saved to love_maybe_lines_stripped the requirements wouldn’t have actually been met. More specifically the tests for this lesson wouldn’t have been able to find this name at all (statements inside the function wouldn’t be executed if it wasn’t called and even if it was, names inside the function would not be available outside unless returned and passed to a new reference).

1 Like

Thanks for the input. Just looking at the date now and understand it might not be lots of help towards the original message. If anything it might create some good dialogue on how to look at the problem different ways. Meaning you could create a function return the results and save it to a variable named love_maybe_lines_stripped.
I understand its more then what needs to be done to get passed this but sometimes exploring and using what you already learned and reinforcing it helps. I know it helps me. I guess in the end just talking through some of the examples in the discuss forum helps me out and makes the lessons stick.
If you know of any other way to do this I would be all ears. Trying to get the most out of Codecademy.

1 Like

For the best user experience, respond to current questions, not moribund topics, as suggested by @tgrtim. A lot of responses end up on deaf ears and only bump dead threads, much to the chagrin of many members.

1 Like