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

whats my problem

i dont get why the system isn't taking my answer when i ran it on the shell and it works perfectly fine

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

2 Answers

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,610 Points

Try solving the challenge in 2 lines of code instead of 3. So modify that 3rd line to be used on the second line. That should get you passed it. :)

Hi there,

Usually, if something works in the shell and the challenge won't accept it, there's something the challenge is specifically asking for. In this case, it's asking that the formatted string be saved to the subject variable. Since the formatting happens after the subject variable is created and isn't stored anywhere, the value of the subject variable isn't actually changed in that line. You can see that in the shell too - if you type subject.format(name), it will give you the correct result, but if you then type 'subject' it will still give you 'Treehouse loves {}', not the formatted string.

You can fix this by just adding the .format to the end of the line where 'subject' is declared:

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

It's worth noting that changing the third line to

subject = subject.format(name)

would also work, but the challenge doesn't like that option - it's looking for you doing it all in one line.

Hope this helps!