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

what what what am I doing wrong. I cannot format the next challenge

can someone show me exactly what I should be writing to be correct in formatting?

strings.py
name = "Margaret"
subject = "Treehouse loves " +  name
status_message = "Treehouse loves  +  { } "
"My { } is { }" .format ("name" ,  "Margaret")
print (status_message .format ( name, Margaret))
print (status_message)

4 Answers

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

It wants you to use string interpolation and assign the string to the variable subject. See my code for the correct formatting.

name = "Jane"
subject = "Treehouse loves {}".format(name)
Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Your code in a project of your own should work. However, the challenge specifically asks you to take the formatted string (all of it) and assign it to a variable... not print it. That's why the challenge fails. If you do something the challenge doesn't specifically ask you to do , the code (even if functional) will likely fail the challenge as it can't properly identify the results. This is what you need.

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

I'll try this-thanks Jennifer!

Andreas Ragnar Hansen
Andreas Ragnar Hansen
1,871 Points

Why gives this code me an error message? Technically is should be right?

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