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

subject.format(name) works in the console, why not in the quiz?

Stupid user issue here: I must be reading the question wrong because as the question states; printing subject.format(name) in the console works. But subject.format(name) in the quiz fails. I'm blind to something simple. What is it?

strings.py
name = "Peter"
subject = "Treehouse Loves {}"
subject.format(name)

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! There are two things going on here. First, you're doing the format on the subject string in place, but it's never assigned back into the subject variable. Use the format on the same line with "Treehouse loves". Secondly, you've used the wrong capitalization on the word "loves". You've capitalized the "L".

When I fix these two issues, your code passes!

Hope this helps! :sparkles:

LOL! I has format on the same line but never changed the capital L. The Challenge editor does not give you much feed back. :) Thanks!

subject = "Treehouse loves" .format(name) Gives the following error: "Bummer! Be sure to use the {} placeholder and the .format() method." This has to be related to the editor used in the course.....no? Thanks in advance!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Oh you're close! But the Bummer message is correct. You've removed the {} from the original code you had. You were supposed to leave it in place. The format method tells Python to insert the value of a variable wherever you have the curly braces, but you no longer have them.

Take a look again at the code you posted here originally. and follow these steps:

  • correct the capitalization of the "L" to "l"
  • put the .format(name) on the same line with "Treehouse loves {}"
  • erase the 3rd line

Here's an example:

name = "Peter"
greeting = "Hi there, {}".format(name)

The variable greeting will now contain the string "Hi there, Peter"

The missing braces in this question are a typo on my part. The braces exist in the actual code and give me the Bummer error.

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

It pasted in one line but is 2 lines in the code.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Now you have an extraneous space.

#you typed
subject = "Treehouse loves {}" .format(name)

#you meant to type
subject = "Treehouse loves {}".format(name)

HAHA! Yup! Thanks for helping the helpless. :)