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!

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

Challenge Task difficulties with .format string.

I'm having difficulties with the .format task challenge. I've tried: variable = "name" name = "Alina" variable = "subject" subject = "Treehouse loves {}" print(subject.format('Alina'))

with no luck. I've even tried format(name) and the task challenge says it is not correct. But I've tried this within the workspace and it worked. Not sure why the challenge task is not accepting it.

variable = "name"
name = "Alina"
variable = "subject"
subject = "Treehouse loves {}"

1 Answer

Christopher Shaw
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,236 Points

Good day, you are over thinking it.

In the first part, you set the name variable.

In the second, we just need set the variable subject with the given string. We then use format to put the name into the placeholder.

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