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 trialImer Pacheco
9,732 PointsWhy does my code not work? Challenge Task 3 of 3 - Shopping List
I'm having trouble figuring out why my code is not passing. Any help would be greatly appreciated. Thanks.
Here is my code:
full_name = "Imer Pacheco"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
for item in greeting_list:
if item == "X":
print(name_list[0])
greeting = " ".join(greeting_list)
print(greeting)
4 Answers
Tree Casiano
16,436 PointsAh, okay. It looks like you have everything correct up till the the for loop. You can complete this challenge without the for loop.
full_name = "Imer Pacheco"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
greeting_list[2] = name_list[0]
greeting = " ".join(greeting_list)
print(greeting)
No need to iterate through a loop. You can just replaces the in the list at the right index. (I tested it in Workspaces, and it does the trick. It should pass the challenge.)
Tree Casiano
16,436 PointsHi Imer. You are getting a syntax error due to improper indentation. Python is unusual in that the indentation is part of the syntax rather than just a convenience for readability's sake. Below is the correct indentation:
full_name = "Imer Pacheco"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
for item in greeting_list:
if item == "X":
print(name_list[0])
greeting = " ".join(greeting_list)
print(greeting)
Tree Casiano
16,436 PointsThe code still doesn't quite work, but this will remove the indentation errors. I can help you more if you need further assistance, but maybe this will be enough to get you on the right track.
Imer Pacheco
9,732 PointsThank you for your response Tree. I'm afraid the way I cut and pasted my code in the browser was not an accurate representation of my code. I actually did have the exact indentation you suggested. Currently, the code evaluates to the following in Workspaces:
Imer
Hi, I'm X
I'm still not clear as to how to replace the "X" with my first name.
Imer Pacheco
9,732 PointsTree, you are amazing! Thank you so much. Turned out to be a simpler solution than what I was doing. I appreciate your guidance :)
Tree Casiano
16,436 PointsYou're very welcome. Glad it worked!