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.

Python Python Basics (2015) Python Data Types Age Calculation

how to do floats

ive forgotten

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

1 Answer

Kourosh Raeen
Kourosh Raeen
23,732 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,732 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.