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

Girri M Palaniyapan
Girri M Palaniyapan
7,829 Points

When 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
STAFF
Kenneth Love
Treehouse Guest Teacher

I 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?

Girri M Palaniyapan
Girri M Palaniyapan
7,829 Points

Hey 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
Kenneth Love
Treehouse Guest Teacher

Girri 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 int 100, you'd used int('100'). Doing int(21 + 34) doesn't make sense because 21 and 34 are already ints.

The same applies to str(), list(), dict(), etc.

Girri M Palaniyapan
Girri M Palaniyapan
7,829 Points

Kenneth Love Thanks a lot. Now I have a better sense of this.

Tom Bedford
Tom Bedford
15,645 Points

Hi 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
Girri M Palaniyapan
7,829 Points

Thanks Tom. I missed out the format bit.