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 trialMUZ140348 Sympathy Makururu
10,209 PointsFinally, create a new variable named email_greeting that puts the treehouse variable and the name variable into the sent
Finally, create a new variable named email_greeting that puts the treehouse variable and the name variable into the sentence "X loves Y" but with treehouse for X and name for Y. Don't forget your spacing!
name= "Sympathy"
treehouse = "Tree" + "house"
email_greeting = "{Treehouse} loves {Sympathy}".format(treehouse, name)
Joey Sadowski
1,361 Pointsname = "joey"
treehouse = "Tree" + "house"
email_greeting = "{}loves {}".format(name , treehouse) That is my code not the first post.
4 Answers
Matthew Carr
11,220 PointsYou can also give each placeholder a name, and then inside format() you pass the variable to the name. For instance, this code would work as well.
name= "Sympathy"
treehouse = "Tree" + "house"
email_greeting = "{first_placeholder} loves {some_name}".format(first_placeholder=treehouse, some_name=name)
MUZ140348 Sympathy Makururu
10,209 PointsThank you. I got it right.
Joey Sadowski
1,361 PointsWhat was the right code
Argenis Sosa
1,701 PointsHi guys, check the code below.
name= "Sympathy" treehouse = "Tree" + "house"
email_greeting = " {} loves {} ".format(treehouse, name)
print(email_greeting)
In python 3.0 the "{}" always stay empty inside the string sentence you write, the " {} " works mainly as a place holders where you will later on assign a specific value to. In this case the values were variables containing values in themselves. You assign the values to the place holders using ".format( ) " at the end of your string (see example up top). Hope I somewhat explained it well and that it was helpful.
Cheers! -AR
Joey Sadowski
1,361 PointsJoey Sadowski
1,361 Pointsname = "joey" treehouse = "Tree" + "house" email_greeting = "{}loves {}".format(name , treehouse)
That is my code. I get "Try Again" any ideas