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 trialNadia Balogou
212 PointsI am getting an error message on format but I am using the method as shown in the video
again not sure if should not be adding the print line but based off of the instructor's video i thought this was the correct way to do it
name = 'Nadia'
subject = 'treehouse loves {} '
print(subject.format('Nadia'))
3 Answers
Jennifer Nordell
Treehouse TeacherNadia Balogou Your instinct to not do the print statement was correct. Code challenges are extremely picky. It's always a good idea to not do anything they don't explicitly ask for. Also, it's important to pay very close attention to the instructions. This includes spelling and capitalization. There's a few things that's causing your code to fail. First, you haven't capitalized the "T" in "Treehouse". Secondly, you have an extra space after your curly braces inside the string. That will also cause it to fail. And third, it shouldn't be printed but the assignment should happen all on one line and should be formatted with your name variable. Take a look:
name = 'Nadia'
subject = 'Treehouse loves {}'.format(name)
Hope this helps!
Philip Cox
14,818 PointsI think you should be using the variable inside the format?
name = 'Nadia'
subject = 'treehouse loves {} '
print(subject.format(name))
akhter ali
15,778 PointsNadia,
Format is not intended to take strings, even though it can, what it does rather is take variables of strings. In your example, you can easily put 'Nadia' in the subject variable because in your print function 'Nadia' is a "fixed" string. Meaning you can only change it in the print function and it will only apply on that particular print function.
You are supposed to use the name variable for the format function to call. Like the example below.
name = 'Nadia'
subject = 'treehouse loves {} '
print(subject.format(name))
What this does is call the name variable from the format function. The use of this is that if your name variable changes from 'Nadia' to 'Ben' for example, then it will take affect everywhere the variable "name" is used.
-Akhter-