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
Theodor Fahami
1,034 PointsHelp with Treehouse challenge, Strings (.format)
I need help with my treehouse challenge, i dont understand how i am supposed to complete it.
The task is: OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again.
And here is my code: name = "Theodor" print("Hello {}", name)
please help
3 Answers
Steve Hunter
57,712 PointsHi Theodor,
I'm back home now, so here's the explanation.
The challenge asks you to complete two tasks. The first is to assign a string representing your name to a variable called name. You've done that; name = "Theodor" - so that's cool.
It then asks you to add the value that variable contains to the string provided using the .format() method.
You've done that too - although there was a typo in the word 'Treehouse' that I pointed out earlier. What is doesn't ask you to do is print anything out. The tests behind the challenge are not expecting to see the code output anything from the line print("Hello, {}", name) - this line needs removing.
You just need to add your name to the "Treehouse loves {}", using the string formatter method, and assign the result of that to a variable named subject:
name = "Steve"
subject = "Treehouse loves {}".format(name)
Make sense?
Steve.
Steve Hunter
57,712 PointsHi Theodor,
You need to use the method .format() which would take your name variable as a parameter.
So, you'd end up with "Treehouse loves {}".format(name)
Make sense?
Steve.
Theodor Fahami
1,034 Pointsname = "Theodor"
print("Hello {}", name)
subject = "Threehosue loves {}".format(name)
I tried this but it returns: Bummer! Be sure to use the {} placeholder and the .format() method.
Am i not doing rigth?
Steve Hunter
57,712 PointsHi Theodor,
I'm out at the moment but will reply when I get home.
However, try correcting the word Treehouse in your string.
Steve
Theodor Fahami
1,034 PointsTheodor Fahami
1,034 PointsSorry for now responding, I have been away for a while.
Thanks for the help! I don't know why i was using the print function re-reading my code now.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGlad you got it sorted.