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 trialAntonio Velardo
Courses Plus Student 111 Pointsplease how do i do that ? Finally, create a new variable named summary that adds the string version of days into "I am {
i don't really understand how it works i am lost
age = 38
days = ( age * 52) * 7
summary =
2 Answers
J.T. Gralka
20,126 PointsThe final step of this code challenge asks you to "Finally, create a new variable named summary that adds the string version of days into 'I am {} days old!'."
The opening and closing curly braces in the string should clue you in that you need to use the format()
method of the str
class to replace the curly brackets with the days
value. See if you can look back in this stage to see how Kenneth uses the format()
method on strings to accomplish something like this.
If you're still stuck, feel free to reply.
Mar Bocatcat
7,405 PointsHi Antonio,
You might want to search up .format() and find more information. But format() is used to fill in the place holders {} in your string like so:
str = 'Antonio' str2 = 'Python' 'Hi! I am {} ,I am learning {}'.format(str,str2) print result will be = 'Hi! I am Antonio, I am learning Python'.
Please let me know if you need any further explanation.
Antonio Velardo
Courses Plus Student 111 PointsAntonio Velardo
Courses Plus Student 111 Pointsplease i am stoked give me more int i don't really understand what to do , i have been stoked two days on this small task
i undetand i need to put format () but it does not make sense to me and i am not even sure i undestood the question
J.T. Gralka
20,126 PointsJ.T. Gralka
20,126 PointsAntonio Velardo,
Imagine we had a script that looked like this:
Notice that we add opening and closing curly brackets inside the
message
string to signify to the format method that that is a placeholder for content. Then, when we call.format()
on the string, we pass in arguments in the order we want them to be inserted into the placeholders in the string.Check out Mar Bocatcat's example below. It's another example of using the
format()
method. This should help you understand the format method forstr
s, and hopefully it helps you answer the code challenge.Good luck!
J.T.
nazia zaman
1,410 Pointsnazia zaman
1,410 PointsHi, i'm stuck on the same thing and have tried everything. Could you just pls give us the solution so we can move forward? It'll be really appreciated! thanks! :)
Mar Bocatcat
7,405 PointsMar Bocatcat
7,405 PointsNazia Zaman,
You might want to search up .format() and find more information. But format() is used to fill in the place holders {} in your string like so: <html> <p>
str ='Nazia' | str2 = 'Python' . this equals to = 'Hi! I am {}, I am learning {}'.format(str,str2) the result will be = Hi! I am Nazia, I am learning Python.
</p>
</html> Please let me know if you need any further explanation