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 trialbrent westley
1,089 Pointshow to do floats
ive forgotten
years = 24
24 * 365
days = 8760
days /7
weeks = 1251
1 Answer
Kourosh Raeen
23,733 PointsHi 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
brent westley
1,089 Pointsbrent westley
1,089 Pointsso theres no thing for floats python just takes care of it
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 PointsYes, I believe using the division operator always returns a float.
Kourosh Raeen
23,733 PointsKourosh Raeen
23,733 PointsAs 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)
andtype(days)
will return<class 'int'>
andtype(weeks)
returns<class 'float'>
. Now, there is afloat()
function in python that converts a number to a float. If you typeyears
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.