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

Help, please :)!

Finally, create 2 new variables, one named estimate that holds the rounded number of decades you've lived and, one named summary that adds the string version of estimate into "I am {} days old! That's about {} decades!" with the correct values added to it.

age = 17
days = 6188
decades = 1.7
summary = I AM STUCK!

5 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Take the string "I am {} days old! That's about {} decades!" and use .format() to plug in the right values.

Also, why are you calculating the days and decades variables manually elsewhere? Let Python do the work for you!

Ann Cascarano
Ann Cascarano
17,191 Points

Remember, variables are our friends! If we create them, we want to use them!

So - for example, if I create a variable to hold the value of my age in years, such as this:

age = 25 (cough cough)

and then I want to know how many days I've been around - so I multiply my age by 52, and then again by 7 like this:

days_old = (age * 52) * 7

I reused my 'age' variable in my 'days_old' variable - and I let python do the calculating for me.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Great comment. One note, you don't actually need the parentheses in age * 52 * 7, since it's multiplication and will move from left to right anyway.

Thanks! Great answers!

Stone Preston
Stone Preston
42,016 Points

it looks like you may have misunderstood the instructions for the decades variable. it needs to be the age variable divided by 10. but you need to use the variables, not just assign it your age divided by 10

decades = age / 10

as far as summary goes you need to call the format function on the string literal "I am {} days old! That's about {} decades!"

using the format function works like this:

some_variable = 10
another_variable = 20
myString = "Variables will be placed here {} and  here {}".format(some_variable, another_variable)

the value of my string after its formatted is "Variables will be placed here 10 and here 20". the variables you pass as arguments to format() get placed whereever {} are in the string. the order you pass in arguments to format matters, so the first variable gets placed in the first {}, the second gets placed in the second {} etc etc

I could not get this to work. I found a silly error that finally fixed it for me. I was using single quotes in my string. So python was reading the first ' at the start of the sentence and then was reading the second ' as the one in "that's". When I changed the first and last from single quotes to double quotes, it worked perfectly. Lesson learned!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Yeah, Python doesn't care if you use ' or " around strings, but you have to start and stop with the same one and you can't use it inside the string unless you escape it (which is ugly).

'valid'
"valid"
'invalid"
'this won't work either'