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 trialtruthseeker
Courses Plus Student 767 PointsNot sure why this is incorrect? name = "Anne" subject + = "Treehouse loves" + "name" Thanks Thanks
Not sure why this is incorrect?
name = "Anne"
subject + = "Treehouse loves" + "name"
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! There's a few minor things going on here. First, you have subject +=
. This would concatenate the string following the equals sign to the string currently in subject
, but this is the first time subject
is declared so there is no string there. Here you only need subject =
.
If we were to fix that and then print out that string that you have coded it would print out "Treehouse lovesname". Note that there is no space between the "loves" and the "name". Furthermore, you are using the string literal "name" instead of of the value in the variable name. Removing the quotes from around the name tells Python to use the value of that variable.
Here's an example:
student = "Jennifer"
greeting = "Hi there, " + student
The string stored in greeting
would be "Hi there, Jennifer". Notice how I included an extra space after the comma in the string literal part to make sure that "Jennifer" wouldn't be smushed up against the comma like this: "Hi there,Jennifer".
Hope this helps, but let me know if you're still stuck!
Oszkár Fehér
Treehouse Project ReviewerHello Truthseeker. The truth is that when you create the subject variable you should assign the string to it notadd the string to it
subject = "Treehouse loves" + name
instead of
subject += ...<rest of the code>
And when you add the name variable to the subject, it should be added the name variable and not the "name" string In your code the subject var it's not yet defined to able to add something to it So the final vode should look like this
subject = "Treehouse loves" + name
I hope it helps you. Happy coding
truthseeker
Courses Plus Student 767 PointsThanks!
truthseeker
Courses Plus Student 767 Pointstruthseeker
Courses Plus Student 767 PointsVery clear. Appreciate your time!