Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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