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 (Retired) Things That Count Things That Count

Things 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!" )
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Like 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 since days is a number which doesn't have a length.

10 Answers

You 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))

Isn't string an object and format a function of the object?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

A string is an object but the actual Python class/function is str().

I 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
Kenneth Love
Treehouse Guest Teacher

Yeah, str is the class/type, not string. string is a library full of awesome little things like ascii_lowercase.

awesome, thanks for the explanation. I look forward to exploring the library full of awesome little things. :-D

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

import string

dir(string)

You know this :)

LOL was just doing that. ;-)

and I have to agree I can see where this is very useful and totally awesome!

i have the same problem :/

someone 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
Kenneth Love
Treehouse Guest Teacher

Only your estimate is wrong. Why are you using len()?

age = 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
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.

Oussama, I got it by removing len() and adding str() to the summary

Oh. Good to know. Thanks!

Kenneth Love AH OK, Thanks Man You're friendly :)

JC Dringenburg Thanks to you

Shadow Skillz
Shadow Skillz
3,020 Points

age =(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
Kenneth Love
Treehouse Guest Teacher

Two 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
Shadow Skillz
3,020 Points

I don't know what I'm doing wrong

Shadow Skillz
Shadow Skillz
3,020 Points

Never 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
Shadow Skillz
3,020 Points

when 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?