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

"Please try using the format command for this task"

I keep running into this error message "Please try using the format command for this task" whenever I try to run it.

Original question: Finally, create a new variable named email_greeting that uses str.format to combine the treehouse variable, the word "loves", and the name variable with spaces between each item. eg: "Treehouse loves Andrew"

name.py
name = ("Daniel")
treehouse = "Tree" + "house"
email_greeting = treehouse + "loves" + name

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

Instead of using string concatenation with the + operator, the question wants you to use the format method on string. Basically, you make a format string with an opening and closing bracket where you want there to be the value of a variable, then you call format on that string and pass it the variables that you want it to replace the brackets with. This should work:

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

Yes thank you! I ended up trying that shortly after submitting the question and it worked. Thank you so much :)