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 (2015) Python Data Types String Formatting

Code Challenge: String Formatting

¨¨¨python name = "Juro" subject = "Treehouse loves {}" print(subject.format(name)) ¨¨¨ I don't find any bad practice with this code. Task is "I want to make the email subject one more time, but this time let's use the .format() method for strings. Go ahead and make your name variable again. Hey, all practice is good practice, right?"

strings.py
name = "Juro"
subject = "Treehouse loves {}"
print(subject.format(name))

4 Answers

Peter Lawless
Peter Lawless
24,404 Points

The code challenge wants you to use the .format() method on the same line that you define the variable "subject". This should work:

name = "Juro"
subject = "Treehouse loves {}".format(name)
print(subject)

FYI there was nothing syntactically wrong with your original code...

I tried

name = "humera" subject = " Treehouse loves { }".format(name) print(subject)

and

name = "humera" subject = " Treehouse loves { }" print(subject.format(name))

But got error in both cases, what could be wrong?

Brian Galassini
Brian Galassini
3,521 Points

I was havign the same problem and then I watched the video again that was right before the quiz. I would suggest watching it again so you can learn properly, but this is what it ended up being:

subject = "Treehouse loves {}" name = "Juro" print(subject.format(name))

I changed the name to yours, but obviously anyone who reads this can change that name to their own.

Kimberly Bennett
Kimberly Bennett
4,627 Points

What worked for me was:

name = "Sara"
subject = "Treehouse loves {}".format(name)