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 (2015) Python Data Types Age Calculation

how to do floats

ive forgotten

age.py
years = 24
24 * 365 
days = 8760
days /7 
weeks = 1251

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Brent you should use the variables you've created at each stage and let python do the calculations:

years = 24
days = years * 365
weeks = days / 7

so theres no thing for floats python just takes care of it

Yes, I believe using the division operator always returns a float.

Kourosh Raeen
Kourosh Raeen
23,733 Points

As Iain said when you divide two numbers you get back a float. Try the lines above in the python shell and then use the type() function to see the class of each variable. type(years) and type(days) will return <class 'int'> and type(weeks) returns <class 'float'>. Now, there is a float() function in python that converts a number to a float. If you type years in the python shell and press enter you will get back 24. Now try the following line in the shell:

years = float(years)

and then type years again in the shell and press enter. This time you get back 24.0 which is a float.