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 trialbruce leong
2,521 PointsGetting an error with this, not sure why.... name = "bruce" subject = "Treehouse loves {}" subject.format(name)
Hi, I'm getting an error with this exercise -
name = "bruce" subject = "Treehouse loves {}" subject.format(name)
Why is this wrong?
name = "bruce"
subject = "Treehouse loves {}"
subject.format("bruce")
3 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Bruce,
There are a couple of things. You are on the right track but I feel you may have misread the instructions. Remember, challenges are very specific and extremely picky.
First, the parameter for theformat()
method should be passed the variable, not a hard-coded string.
Second, the instructions say to use the format()
method on the string, but you are using it on the variable.
Give it another shot with this in mind. I'm sure you'll get it.
Keep coding! :)
AJ Salmon
5,675 PointsThe challenge wants you to assign the string "Treehouse loves bruce" to the variable subject. Here, you're using .format(), but that doesn't actually change the variable subject to the desired string. So in your case, subject is still equal to "Treehouse loves {}". You can use .format() directly after your string, like this:
>>> name = 'Kevin'
>>> sentence = "{} loves tacos".format(name)
>>> sentence
>>> 'Kevin loves tacos'
That way, the format function is performed and assigned to the variable all on one line. Hope this helps!
bruce leong
2,521 PointsGot it! I just wasn't reading the directions correctly. Thank you everyone.