"Customizing the WordPress Admin Area" was retired on July 6, 2019.

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

OK, 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
Kevin Ohlsson
4,559 Points

These 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
Chris Freeman
Treehouse Moderator 68,441 Points

Hey 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
Kevin Ohlsson
4,559 Points

Thanks 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
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The .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)

thanks alot for help :)

Diana Mendez
Diana Mendez
2,833 Points

Pleases 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
Chris Freeman
Treehouse Moderator 68,441 Points

Hi 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
Diana Mendez
2,833 Points

Hmmm 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
Chris Freeman
Treehouse Moderator 68,441 Points

Too much "Love". It should be lowercase! Way to keep at it!

Diana Mendez
Diana Mendez
2,833 Points

Chris Freeman Haaay!! sooo siiiimple (+_+) Thanks a lot!!

The 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..

thank you :)

Jonathan McKee
Jonathan McKee
826 Points

The way some of these questions are written is confusing

Why 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
Chris Freeman
Treehouse Moderator 68,441 Points

The 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.

2 Good

Challenge 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"

Challenge 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
Jon Helmus
7,312 Points

Part 2 should look something like this.

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

THe {} are going to place whatever you pass through the parenthesis.

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

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Hi 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.