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

Narek Grigoryan
Narek Grigoryan
717 Points

String formatting

this is frustrating!

name = "narek" 
treehouse = "Tree"+ "house"
"Treehouse loves Andrew = email_greeting= ("{} loves {}".format(name, treehouse))

when you do string-3 it say nomb 1 oops not passing! its look like teasing me ! any ideas? thanks!

Aaron Loften
Aaron Loften
12,864 Points

Hey Narek. Could you post your code in the question a little cleaner?

If you indent your code by four spaces, it will format in a way that is easier to read. Right now, it is hard to tell what is what. I think I see what the problem is, but id like to see it better formatted before answering.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I reformatted your code by wrapping the code block with

```python

```

6 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

In your latest attempt:

1
name = "narek"
2
treehouse = "Tree"+ "house"
3
email_greeting = "{} loves {}" .format(name, treehouse)

There are two errors: A space between the string and the .format() method. And the arguments to the .format() method are reversed giving "narek loves Treehouse", which may be true but it is not what they're looking for.

email_greeting = "{} loves {}".format(name, treehouse)
Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Remember that everything to the right of the equals sign gets put into the variable on the left of the equals sign.

You started out by writing out the string "Treehouse loves Andrew". We don't want to write this out literally, we want to create this string of text programmatically, and we want to use your name not Andrew's. This line of code should just start with the variable name you're putting everything into - email_greeting - and then the equals sign. The next part works right. You've wrapped it all in parenthesis, which is unnecessary, but still works. The whole line of code without the extra parentheses could look like this

email_greeting = "{} loves {}".format(treehouse, name)
Narek Grigoryan
Narek Grigoryan
717 Points

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

Narek Grigoryan
Narek Grigoryan
717 Points

Thanks ! you are phyloGenies :)

Take out the brackets;

name = "narek" 
treehouse = "Tree"+ "house"
email_greeting = "{} loves {}" .format(name, treehouse)

Should work. Let me know.

Narek Grigoryan
Narek Grigoryan
717 Points

Nano narek more43 Challenge Task 3 of 3

Now let's practice using string formatting and placeholders.

Finally, create a new variable named email_greeting that uses str.format to combine the treehouse variable, the word "loves", and the name variable with spaces between each item. eg: "Treehouse loves Andrew" Important: The code you write in each task should be added to the code written in the previous task. Preview Get Help Check Work name.py

This the very nice instructions from teacher... lol its bean 4-6 hours i cant get trou

Narek Grigoryan
Narek Grigoryan
717 Points
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> name = "narek"
treehouse = "Tree" + "house"
treehouse loves narek = email_greeting = ("{} loves {}".format (name, treehouse))
SyntaxError: multiple statements found while compiling a single statement
>>> 

help pls!

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Two things:

1) There shouldn't be anything to the left of email_greeting. That is the name of the variable you're putting everything into. We hope that it will be the string "Treehouse loves narek" inside that variable, you shouldn't be typing it out explicitly

2) Inside the .format method you're making the same mistake again with the variables in the wrong order - it should be (treehouse, name) not (name, treehouse). The repl won't object to this but you'll need to have them in the right order to pass the challenge.

name = "narek" 
treehouse = "Tree"+ "house"
email_greeting = "{} loves {}".format(treehouse, name)

Should work. You had an extra pair of brackets.

Let me know

Narek Grigoryan
Narek Grigoryan
717 Points

Challenge Task 3 of 3

Now let's practice using string formatting and placeholders.

Finally, create a new variable named email_greeting that uses str.format to combine the treehouse variable, the word "loves", and the name variable with spaces between each item. eg: "Treehouse loves Andrew"

.................. Bummer! Try again!.................!!!!!

1 name = "narek" 2 treehouse = "Tree"+ "house" 3 email_greeting = "{} loves {}" .format(name, treehouse)

Hello guys, i do exactly like you but, this time stupid prog says TRY AGAIN, AGAIN AND AGAIN, this is unbelievable! thanks to everyone ! dont spend your time. I will let it go.

Can you copy paste your new code?

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

You have the variables in the wrong order. It should be format(treehouse, name) not format(name, treehouse).

Not to be a jerk, but I've mentioned this issue two times already in this thread.