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 (Retired) Ins & Outs Ins & Outs

How do I combine the two variables name = Elizabeth and treehouse = (tree+house) into "X loves Y"?

I can't figure out how to combine the two variables into the sentence "X loves Y" and substitute them for X and Y.

name.py
name = ("Elizabeth") 
treehouse = ("Tree" + "house")
email_greeting = ("x loves y") if x = ("name") and y = ("treehouse")

3 Answers

Hi Elizabeth!

All you should need to do to pass the challenge is something like the following.

email_greeting = (name + " loves " + treehouse)

I hope this helped you out and I hope you are having a great day! Keep it up!

-Luke

Darren Joy
Darren Joy
19,573 Points

What Luke Glazebrook said above. It's probably easier than what you are attempting...

My comments...

This line here:

email_greeting = ("x loves y") if x = ("name") and y = ("treehouse")

is trying to do too many things at once. And in a weird order

You are trying to define a variable as "x loves y" but that is a string so it will print out just as it is i.e x loves y rather than Elizabeth loves treehouse. And the if statement needs to be in the following format:

if(condition) {do something}

If you were going to do something with the logic you presented it would be more like:

You would have to define x as the variable name and y as the variable treehouse, then test that they were the same as defined, then do something with that knowledge...

 if (x === name && y === treehouse) {
email_greeting = x + " loves " + y; }

I imagine you are envisioning that x and y are inputs from the user and you are checking to see if they meet some name stored 'in the system'?

PS my syntax might be off I am going through PHP and javascript right now, but you get the idea with the for statement I think

Sai Kiran Dasika
PLUS
Sai Kiran Dasika
Courses Plus Student 7,278 Points

You can concatenate the string just like you do in javascript.

email_greeting = name + " loves " + treehouse

Hope this helps you.