Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!