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 concatenation

Need Help!

What's wrong with the my attached code

strings.py
name = "Ayaz"
subject ="Treehouse loves "

subject + name

3 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

You need to concatenate the strings: You didnt do it correctly:

subject = "Treehouse loves " + name

what is the problem in "subject + name" ?

"subject+name" would work in real life... but sometimes the tests are looking for a more specific way of solving the problem, it depends on the course how picky they are about writing the code they are looking for or just getting the right answer at the end

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

Ayaz Alam There's a couple of problems. Now you could have done it like this:

name = "Ayaz"
subject ="Treehouse loves "

subject = subject + name

That would have set the variable subject to the correct string. It wants subject to be equal to "Treehouse loves Ayaz". However, even though that would work outside the challenge. It doesn't work inside the challenge. Keep in mind that challenges are super picky.

So Cindy Lea is correct. To pass the challenge the string assignment to subject must be done all on one line.

name = "Ayaz"
subject ="Treehouse loves " + name

Happy coding! :dizzy: