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 trialyeshi chopal
1,445 PointsOK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the va
need help, appreciated !
Kevin Ohlsson
4,559 PointsThese code exercises should be updated with more variants as 'correct' answers. I'ts very annoying having to troubleshoot for errors beyond the errors that python would give me.
For example. This code will fail with workspaces:
name = 'Kevin'; subject ='Treehouse loves {}.'.format(name)
But this code will work:
name = 'Kevin'; subject ='Treehouse loves {}'.format(name)
see the difference? Yeah, it's annoying and should already have been accounted for in the system.
Chris Freeman
Treehouse Moderator 68,441 PointsHey Kevin Ohlsson, it can be frustrating at times. I have also been driven crazy in search of a missing space or punctuation. This is part of programming unfortunately.
I agree that multiple correct answers should be accepted and, when appropriate, Kenneth updates the challenge checker to do so.
In this case, the difference of an additional trailing period is not an alternative correct answer. The task description asks for a specific string to be created, excluding the trailing period. Coding toward a specified goal as mentioned in the task description is part of the training for the sometimes pixel-perfect obsessed jobs in your future.
Please don't be discouraged! We all hit these "walls" only to face-palm when the answer is revealed. Sometimes it's complicated and sometimes it's just an extra period. Keep at it!! Every struggle is growth and you are a better programmer for it. Good luck!!!
Kevin Ohlsson
4,559 PointsThanks Chris,
I guess you have a point. In regards to programming it is useful to be pedantic about details and if that's what this exercise demonstrates that's a good thing.
Cheers!!
8 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe .format()
method on a string says to fill in each placeholder { }
with an argument to format()
. In this case, you only need to provide your name
variable from Task 1 as an argument:
# Task 1 of 2
# I want to make the email subject one more time, but this time let's
# use the .format() method for strings.
# Go ahead and make your 'name' variable again.
# Hey, all practice is good practice, right?
name = "Chris"
# Task 2 of 2
# OK, so now use '.format()' on the string "Treehouse loves {}" to put
# your name into the placeholder. Assign this to the variable 'subject' again.
subject = "Treehouse loves {}".format(name)
yeshi chopal
1,445 Pointsthanks alot for help :)
Diana Mendez
2,833 PointsPleases Help!i I've done this over and over again and it doesn't work! I'm stuck
name = "Diana"
subject = "Treehouse loves {}" .format(name)
[MOD: added ```python formatting. -cf]
Chris Freeman
Treehouse Moderator 68,441 PointsHi Diana Mendez! You are VERY close. There is an extraneous space between the string and the .format(name)
method. Remove this space and it should pass. Good Luck!
Diana Mendez
2,833 PointsHmmm Thanks for your quick reply. I fixed the space and It keeps saying: Bummer! Be sure to use the {}
placeholder and the .format()
method.
name = "Diana"
subject = "Treehouse Loves {}".format(name)
Chris Freeman
Treehouse Moderator 68,441 PointsToo much "Love". It should be lowercase! Way to keep at it!
Diana Mendez
2,833 PointsChris Freeman Haaay!! sooo siiiimple (+_+) Thanks a lot!!
mkmk
15,897 PointsThe format string method fills in the curly braces with its arguments.
ie. "{} is a course at {}".format('python', 'treehouse')
alternatively, variables holding strings may be used in place of the string arguments in parentheses used above..
yeshi chopal
1,445 Pointsthank you :)
Jonathan McKee
826 PointsThe way some of these questions are written is confusing
A X
12,842 PointsWhy wouldn't this be a "more correct", or at least equally correct, why of solving this code challenge? I say more correct because I'm assigning a value to the variable subject, and then in the next line I'm formatting that assignment (if I'm understanding what's happening correctly).
name = "Godzilla"
subject = "Treehouse loves {}"
subject.format(name)
Chris Freeman
Treehouse Moderator 68,441 PointsThe first issue is the string result of the formatting is not preserved by assigning to a variable. This can be fixed using:
subject = subject.format(name)
That would normally be sufficient. This particular challenge wants to verify understanding of using the format directly on the string so it will reject assigning formatting subject
on a second line.
Ary de Oliveira
28,298 Points2 Good
Ary de Oliveira
28,298 PointsChallenge Task 1 of 2
I want to make the email subject one more time, but this time let's use the .format() method for strings. Go ahead and make your name variable again. Hey, all practice is good practice, right?
name = "Ary de Oliveira"
Ary de Oliveira
28,298 PointsChallenge Task 2 of 2
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 = "Ary de Oliveira" subject = "Treehouse loves {}".format(name)
Jon Helmus
7,312 PointsPart 2 should look something like this.
subject = "Treehouse loves {}".format(name)
THe {} are going to place whatever you pass through the parenthesis.
VELA ZUNGU
Courses Plus Student 173 Pointsname = "Vela" subject = "Treehouse loves {}".format("Vela")
Chris Freeman
Treehouse Moderator 68,441 PointsHi VELA ZUNGU! Thank you for participating in the Community forum. It will serve you well in asking questions when you're unclear about something. It will also help to reinforce what you know as you explain to others what concept they might be missing.
We discourage posting the solution code to the challenges or, more importantly, we discourage simply posting code with no explanation. In that regard, your post will be removed.
Terrell Phinazee
1,675 PointsTerrell Phinazee
1,675 PointsThanks for the help!!