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) Ins & Outs Ins & Outs

Finally, 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.py
name= "Sympathy"
treehouse = "Tree" + "house"
email_greeting = "{Treehouse} loves {Sympathy}".format(treehouse, name)

name = "joey" treehouse = "Tree" + "house" email_greeting = "{}loves {}".format(name , treehouse)

That is my code. I get "Try Again" any ideas

name = "joey"

treehouse = "Tree" + "house"

email_greeting = "{}loves {}".format(name , treehouse) That is my code not the first post.

4 Answers

You 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)

Thank you. I got it right.

What was the right code

Argenis Sosa
Argenis Sosa
1,701 Points

Hi 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