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

NameError: name 'subject' is not defined

I am not sure what I am doing wrong here. I have tried the same code with str() instead of print as well

strings.py
name = "Jason Martino"
print("Treehouse loves {}".format("name"))

2 Answers

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

The challenge explicitly states that you need to assign the string to the variable named subject. We do this with the following code. Remember, keep your name variable as is.

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

Thank you Jennifer!

Kourosh Raeen
Kourosh Raeen
23,733 Points

You should pass the name variable to format() without quotes. Also, instead of displaying the string you need to assign it to a variable named subject:

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