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 trialJC Dringenburg
2,903 PointsThings That Count Task 3 of 3
What am I doing wrong? I have tried estimate.string, estimate + string, string("I am (estimate) days old!"). Thanks ahead of time.
age = 28
days = (age * 52 / 7)
estimate = round(len(days))
summary = estimate + string("I am {} days old!" )
10 Answers
James Andrews
7,245 PointsYou need to use the string.format function to insert the estimate into the {} position
age = 28
days = (age * 52 / 7)
estimate = round(days)
summary = string("I am {} days old!".format( estimate))
Kenneth Love
Treehouse Guest Teacherstring()
isn't a function in Python.
James Andrews
7,245 PointsIsn't string an object and format a function of the object?
Kenneth Love
Treehouse Guest TeacherA string is an object but the actual Python class/function is str()
.
James Andrews
7,245 PointsI see what you're saying. So when I am talking about string object methods I should talk about them as str.format() and not string.format()?
Kenneth Love
Treehouse Guest TeacherYeah, str
is the class/type, not string
. string
is a library full of awesome little things like ascii_lowercase
.
James Andrews
7,245 Pointsawesome, thanks for the explanation. I look forward to exploring the library full of awesome little things. :-D
Kenneth Love
Treehouse Guest Teacherimport string
dir(string)
You know this :)
James Andrews
7,245 PointsLOL was just doing that. ;-)
and I have to agree I can see where this is very useful and totally awesome!
oussama
6,484 Pointsi have the same problem :/
oussama
6,484 Pointssomeone helps me to get the quiz ? :(
age = 16 days = (age * 52 / 7) estimate = round(len(days)) summary = "I am {} days old!".format( estimate)
Kenneth Love
Treehouse Guest TeacherOnly your estimate
is wrong. Why are you using len()
?
oussama
6,484 Pointsage = 16 days = (age * 52 / 7)
estimate = round(days)
summary = str("I am {} days old!").format(estimate) ===> :D This is the solution :D Yeees
Kenneth Love
Treehouse Guest Teacher"I am {} days old!"
is already a string, though, so you don't need to wrap it with str()
either.
JC Dringenburg
2,903 PointsOussama, I got it by removing len() and adding str() to the summary
JC Dringenburg
2,903 PointsOh. Good to know. Thanks!
oussama
6,484 PointsKenneth Love AH OK, Thanks Man You're friendly :)
oussama
6,484 PointsJC Dringenburg Thanks to you
Shadow Skillz
3,020 Pointsage =(26) days = (age *52*7) decades = (age / 10) estimate = round(decades) summary = ('I am {} days old! That is about {} decades!'. format (age, decades))
Kenneth Love
Treehouse Guest TeacherTwo things.
First, you don't need nearly that many parentheses. They don't look like they're breaking anything, but they're definitely cluttering up your code.
Secondly, the string wants days
, not age
.
Shadow Skillz
3,020 PointsI don't know what I'm doing wrong
Shadow Skillz
3,020 PointsNever mind I got it
age = (26) days = (age *52*7) decades = (age / 10) estimate = round(decades) summary = ('I am {} days old! That is about {} decades!'. format (days, estimate))
Shadow Skillz
3,020 Pointswhen i post my answer how do i get it to look like when I'm solving the question it always comes out like my previous post?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherLike James Andrews pointed out, you have to use the
.format()
method on the string.You also don't need to get the
len()
of days sincedays
is a number which doesn't have a length.