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

I am stuck at this, I ran the same piece of code on my local IDE and it works fine somehow it's throwing an error here

Question:

OK, now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject (so start with subject =).

Code:

name= 'Chandana' subject = "Treehouse loves {}" print(subject.format(name))

Error:

Bummer! Be sure to use the {} placeholder and the .format() method.

did you find any solution?? i tried same with below command: name="Gaurav sharma" subject="treehouse loves {}" print(subject.format(str(name)))

worked in workspace, but failing here. not sure if i have a wrong understanding of question.?? error is : Be sure to use the {} placeholder and the .format() method. task is to : format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject (so start with subject =). and name is defined already.

4 Answers

if it doesn't ask you to print, don't print. just set the variables as requested.

instead of subject = "Treehouse loves {}" print(subject.format(name)) try it all on one line, i think that's what it wants. subject = 'treehouse....{}'.format(name) like you have.

I was just playing around with the solution to make it work! but actually even without print it doesn't work and gives the same error!

James is correct, .format() only works when it is attached to a string, and it has variables in its parameters to stick in the string.