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
Stephen Jennings
4,824 PointsPython Strings
I'm not sure why I'm getting hung up on this question, but I cannot seem to get the "estimate" variable to display in a string. Here is the question:
Challenge Task 4 of 4
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 (wrong) answer:
Bummer! Your estimate doesn't seem to be in your summary!
age = int(28)
days = int(28*52*7)
decades = float(age / 10)
estimate = round(decades)
summary = str("I am {days} days old! That's about {estimate} decades!")
1 Answer
Maxim Andreev
24,529 PointsYou're using {} wrong, it is used like this:
"I am {} days old! That's about {} decades!".format(days, estimate)
you add your variables within the brackets of .format() which follows a string. The {} are then replaced by the values of the variables, in order.
Also you don't need to convert something that's an int into an int, or something that's already a string into a string
PS wrap your code so it's easier to read
cheers
Stephen Jennings
4,824 PointsStephen Jennings
4,824 Pointsfacepalm of course! Can't believe I forgot that, it was only a few videos prior haha. Thanks for the help!