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 Formatting

William Heimann
William Heimann
1,764 Points

python basics, strings.py, what am I doing wrong?

I can't seem to figure out where my mistake is. I have looked at the video and the notes a few times and still it says I'm wrong. I put the code into the console on workspaces and it seemed to work. where is my mistake?

strings.py
name = "Will"
subject = "Treehouse loves {}." 
subject.format(name)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

You are very close. This challenge wants the format() on the same line. Also be sure the string is correct (no period at the end)

name = "Will"
subject = "Treehouse loves {}".format(name)
William Heimann
William Heimann
1,764 Points

ok thank you for the help. I originally didn't have the period but after reading a few other posts I thought that might fix it. One more question, the challenge wants the .format on the same line but it worked in the console when written in 2 lines, so which way is correct in real world application?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

In real code both are accepted. In creating the challenges sometimes the graders are overly specific to verify you learn a certain style.

In a later challenge, the following style of putting them on two lines is accepted:

name = "Will"
subject = "Treehouse loves {}"
subject = subject.format(name)

Which you choose depends on what makes the code easiest to read.