Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Shopping List Lists and Strings

On task 3/3 I keep getting the message that task one is no longer passing although I've done nothing to change it

Can you clear this up?

greeting_list.py
full_name = 'Daniel Strong'
name_list = full_name.split()
#greet = "Hi, I'm" + full_name[0]
greeting_list = "Hi, I'm" + name_list[0].split() #+ name_list[0].split() #+ full_name[0].split()
greeting = ''.join(greeting_list)

2 Answers

Mikael Enarsson
Mikael Enarsson
7,056 Points

You are going about this in the wrong way. Outlining the tasks in the challenge:

  1. Create a string with your name and split it into a list. This one is fine.

  2. Split the string "Hello, I'm X" on the spaces. You aren't doing this in your code.

  3. Insert your name in the position that X has in greeting_list and join it into a string, This is where you went wrong, I think you went back and replaced the code from task two with

greeting_list = "Hi, I'm" + name_list[0].split()

trying to concatenate a string with a list item (which is apparently not allowed, and thus a syntax error, which is why you got "Task 1 no longer passing").

What they want you to do is take the greeting list you created earlier, and replace 'X' with the first item in name_list (by assigning the value at the first position in name_list to the list position in greeting_list that holds 'X'). You're almost there, by the looks of it.

The rest is fine, mostly.

Oh, and sorry if I sound a bit gruff, but it's late-ish over here. I hope you can forgive me ^^

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Adding a list item to a string, assuming the item is a string itself, is fine. The problem is the order these actions are done in.

Here's how Python sees it.

  1. Oh, hey, a string. OK. "Hi, I'm"
  2. Oh, wait, they want to add something to it
  3. Agh! They want to split the thing they're adding. OK, let's do that (this creates a new list)
  4. Now to add these things together....waitaminute! I can't add a list to a string!
  5. Give up and cry.

Now doing it with an explicit order-of-operations would make it work.

greeting_list = ("Hi, I'm " + name_list[0]).split()

Also, you want a space before the string ends, so I've added that in.

Mikael Enarsson
Mikael Enarsson
7,056 Points

Aah, of course, I should have seen that! I still have some way to go, it seems.

Thank you so much, Mikael and Kenneth! That worked great and was surprisingly easy.