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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Girri M Palaniyapan](https://uploads.teamtreehouse.com/production/profile-photos/1229512/micro_1270683_10153204996965338_1664753481_o.jpg)
Girri M Palaniyapan
7,829 PointsWhen I key in the last line, why do I get the error message that the first task of defining the age variable fails.
age = int("21")
days = int( age * 52 * 7 )
decades = ( age / 10 )
estimate = int(round( decades))
summary = ("I am {} days old! That's about {} decades! ".(estimate.decades))
Thanks
2 Answers
![Kenneth Love](https://uploads.teamtreehouse.com/production/profile-photos/710512/micro_TeacherShoot-Kenneth.jpg)
Kenneth Love
Treehouse Guest TeacherI think our CC engine was having some problems when you tried this originally. You do have a syntax bug in your code, though. Your last line doesn't use the format
method, as it should.
Also, why are you doing so much work? Why use int("21")
instead of just 21
? Why int(round(decades))
instead of just round(decades)
since round()
always returns an int anyway?
![Tom Bedford](https://secure.gravatar.com/avatar/3f802301c7abf5104ab6daa478638eb5?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tom Bedford
15,645 PointsHi Girri
You are getting that error message as the code for the last question has some mistakes, unfortunately the error message isn't pointing you in the right direction.
As an example similar to what the last question is asking - if I had two variables, day
and time
that needed inserting into a string I would do it like this:
date = 30
time = 10
summary = "It is the {}th September at {} o'clock".format(date, time)
Make sure you have the correct code for formatting the values you are inserting into the string, also make sure you are inserting the correct variables.
![Girri M Palaniyapan](https://uploads.teamtreehouse.com/production/profile-photos/1229512/micro_1270683_10153204996965338_1664753481_o.jpg)
Girri M Palaniyapan
7,829 PointsThanks Tom. I missed out the format bit.
Girri M Palaniyapan
7,829 PointsGirri M Palaniyapan
7,829 PointsHey Kenneth, Thanks for the reply.
I am confused about when I need to use int. Supposing I am adding two numerical values say 21 + 34 and this is going to assigned to variable number_1
should I write number_1 = int (21 + 34) ?
Thanks
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherGirri M Palaniyapan You only need to use
int()
when you want to make something that's not an int into an int. Like, turning the string'100'
into the int100
, you'd usedint('100')
. Doingint(21 + 34)
doesn't make sense because21
and34
are already ints.The same applies to
str()
,list()
,dict()
, etc.Girri M Palaniyapan
7,829 PointsGirri M Palaniyapan
7,829 PointsKenneth Love Thanks a lot. Now I have a better sense of this.