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 trialCordell Key
1,130 PointsHelp with Python - String Challenge
Why can I not run this code, I believe it may be the syntax?
name = 'Cordell' subject = "Treehouse loves { }" print(subject.format (name))
name = 'Cordell'
subject = "Treehouse loves { }"
print(subject.format(name))
4 Answers
Bryan Reed
11,747 PointsIf you remove the space inside the {} it should work :)
Mckenzie Hessel
Full Stack JavaScript Techdegree Graduate 20,437 PointsDid you figure it out? You can also simplify and make it two lines of code:
name = "Cordell" print("Treehouse loves {}.format(name)")
Arindam Roychowdhury
3,244 Points"Treehouse loves {name}".format(**{'name':name})
Note the **
>>> name = 'Cordell'
>>> subject = "Treehouse loves { }"
>>> subject.format(**{'name':name})
'Treehouse loves Cordell'
Cordell Key
1,130 PointsHi Arindam - Thanks for the help, one the "**" why are these needed? I haven't learned this syntax yet.
Cordell Key
1,130 PointsI just ran my code in Workspace to see if would run, and it did without any problems.
name= 'Cordell' subject = "Treehouse loves {}" print(subject.format(name))
Cordell Key
1,130 PointsCordell Key
1,130 PointsHi Bryan - Sorry removing the space from {} did not work, but I appreciate the help!
Bryan Reed
11,747 PointsBryan Reed
11,747 PointsStrange, this worked for me: