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 trialruslanfarutdinov
198 PointsPython Basics 2nd Challenge
First three tasks ask you to: 1) create age variable with your age 2) create days variable with your age*52*7 3) create decades variable by dividing your age by 10
And the last task is to: 4) create estimate variable that rounds how many decades you've been alive 5) create summary variable that says "I am {} days old! That's about {} decades!"
I am not sure what I am doing wrong.
age = 23
days = 23*52*7
decades = 23/10
estimate = round(decades)
summary = "I am " + days + " days old! That's about " +
estimate + " decades!"
5 Answers
Eric Gernux
1,534 PointsFor part 5 copy this exact code and it should work:
summary = "I am {} days old! That's about {} decades!".format(days,estimate)
Bruce Klein
Courses Plus Student 5,073 PointsYou need to use the variables:
days = age*52*7 decades = age/10
ruslanfarutdinov
198 PointsThat makes sense. But even with these changes, it says something is wrong. Perhaps I don't fully understand the question, here it is just in case:
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.
My updated code: age = 23 days = age*52*7 decades = age/10 estimate = round(decades) summary = "I am " + days + " days old! That's about " + estimate + " decades!"
Bruce Klein
Courses Plus Student 5,073 PointsIf you need an estimate, try:
estimate = decades - (decades % 10)
This will set estimate equal to decades minus the remainder of decades divided by 10.
ruslanfarutdinov
198 PointsStill doesn't work.
Eric Gernux
1,534 PointsIn one of the previous lessons they talk about the .format after strings
The answer should look like this:
summary = "I am {} days old! That's about {} decades!".format(days,estimate)
ruslanfarutdinov
198 PointsSo would the answer look like this in your opinion:
age = 23 days = age*52*7 decades = age/10 estimate = round(decades) summary = "I am " + days + " days old! That's about " + estimate + " decades!".format(days,estimate)
If so, it still isn't working.
Eric Gernux
1,534 PointsYou need the curly brackets in the answer still the .format(days,estimates) fills the first curly brackets with days and the second with estimates.
ruslanfarutdinov
198 PointsEric, I am not sure what you mean?
Kenneth Love
Treehouse Guest TeacherIt's failing because of you having estimate + " decades!"
on a new line. Python doesn't automatically move from one line to the next, so you can't just throw new lines in willy-nilly. :D
ruslanfarutdinov
198 Pointsruslanfarutdinov
198 PointsIt worked! Thanks a lot!