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 trialRyan Ferguson
4,786 PointsI cannot for the life of me figure out how to make this greeting variable.
I've tried a few ways and even asked someone who was pretty familiar with Python and we couldn't figure out what it wanted. Anyone mind helping out? Been stuck on it for days.
full_name = "Ryan Ferguson"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
greeting = " ".join(greeting_list[0,1] + name_list[0])
2 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Ryan
I did it like this
full_name = "Ryan Ferguson"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
greeting = " ".join(greeting_list).replace("X", name_list[0])
Charlie L.
10,120 PointsJust to help you debug your original code. You want to be careful about how list splicing works.
list[start:stop:step] in which the stopped part is not included.
Right now the greeting variable outputs: "Hi, Ryan" instead of "Hi, I'm Ryan"
Ryan Ferguson
4,786 PointsJust out of curiosity, how come my calling of those indexed elements in variable "greeting_list[0,1]" didn't work to pull in everything but the "X"?
Ryan Ferguson
4,786 PointsRyan Ferguson
4,786 PointsThis worked for me. Thanks, Andreas!
I'm a little confused though because I don't recall the replace() function being taught in the courses leading up to this challenge, unless I overlooked it, which would explain a lot. =P
Thanks again!