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 trialAntonio Hermida
1,225 PointsString Formatting
This is a very simple problem, but I am not sure what I am doing wrong. The code challenge asks me to create a string, label it subject, and then use .format() in order to change what is in the curly brace. I keep getting errors though.
name = "Antonio"
myString = "Treehouse loves {}"
subject = myString.format(name)
3 Answers
Travis Bailey
13,675 PointsTechnically your answer is correct, but it might be a bug in the way the challenge is checking the answer. Instead of breaking your answer into three lines, try doing it in two. There's no need to store 'myString' as you can perform what you do in lines 2 & 3 in one line.
For example:
name = 'Arthas'
subject = 'Treehouse loves {}'.format(name)
Again, while your answer is technically correct I think it's more common to see string formatting in the example I gave above.
Shawn Denham
Python Development Techdegree Student 17,801 PointsThe first question asks you to create the name variable so
name="Shawn"
The second question asks OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again.
name="Shawn"
subject = "Treehouse loves {}".format(name)
Hope that helps
Melanie Villela
3,048 PointsI have a question. Why wouldn't this work:
Antonio Hermida
1,225 PointsAntonio Hermida
1,225 PointsThanks guys, that worked. I did not know that it could be written in just 2 lines of code like that. Greatly appreciated.