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

Should I round?

I am doing my calculations and I keep getting the answer wrong. Should I round my number?

age.py
years=27
days=9855
weeks=1407.8571428

1 Answer

Charlie Gallentine
Charlie Gallentine
12,092 Points

So the error is not in your calculations, rather it is because you are doing them instead of the program. You are assigning values which you have calculated to "years", "days", and "weeks" instead of using them to create one another. Python will do the calculations for you with a little algebraic logic:

years = 19 # You set the initial variable, in this case your age in years
days = years * 365 # Python will calculate the number of days by multiplying "years" by 365
weeks = days / 7 # Python will calculate the number of weeks by dividing "days" by 7

I do not think you should have to do any external calculations for any of the challenges, after all, that is why we program computers to do them!

Hope that helps!