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 do this in python.

how do i create an email_greeting variable with loves and treehouse in it

name.py
name=("Whats your name")
treehouse="Tree" + "house"
xtreehouse=email_greeting="treehouse loves name"

1 Answer

You'll actually get to this in just a few lessons, its cool that you're thinking a head though and looking to add more functionality to your code.

The user input: It looks like you want users to input their name into the name variable. You can let them do this by using the input function.

To add variables into a string: There are actually a couple of ways to do this but using .format() is the most pythonic.

Here is what your code would look like using the two functions I mentioned.

name = input("What is your name? ")
treehouse = "tree" + "house"

email_greeting = "{} loves {}".format(treehouse, name)

print(email_greeting)

So the syntax for input is the word input followed by a string in quotes and parentheses.

The syntax for format is use brackets where you want your variables to go in the string (don't forget your quotes; either double or single work), then list your variable names following the period and the word format surrounded by parentheses. You can do more with format but you'll get that during lessons.

I also added a print statement so that you can see how your email greeting turned out. The syntax for that is print followed by your variable in parentheses.