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

paul cullum
paul cullum
360 Points

ins outs

where am i going wrong ? im stuck :/

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

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Format applies only to the string it is attached to. Your code is only formatting the last field. Try:

email_greeting = "{} loves {}".format(treehouse, name)

Alternatively, you could have used:

email_greeting = "{}".format(treehouse) + " loves " + "{}".format(name)

But that is must less efficient!

paul cullum
paul cullum
360 Points

ok than you , i got it in the end anyway :)

email_greeting = str("{0}" + " loves " + "{0}).format(treehouse,name)

Worked :)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Your solution builds a string to use as the format string, then formats that string. This is less efficient unless you are reusing the format base string as was done in the String Factory challenge:

# least efficient, build string from string built from static elements
str_format = str("{0}" + " loves " + "{1}")
# a little better, removes unnecessary string wrapper
str_format = "{0}" + " loves " + "{1}" 
# or better yet
str_format = "{0} loves {1}"  # no need to construct a string from static parts

email_greeting = str_format.format(treehouse, name)

Two other notes: The format field names should be numbered {0} loves {1}, or left both blank {} loves {}. Also there is a missing trailing " in your code (probably just cut and paste miss).