Python Python Basics (2015) Python Data Types Age Calculation

David Lassen-Diesen
David Lassen-Diesen
184 Points

In Python basics it asks you to add your age *365 for 365 days in a yr , it then asks you about variable days

In Python basics it asks you to add your age *365 for 365 days in a yr (excluding leap yr), it then asks you about variable days in the formula, this is where i need a bit of help please.

age.py
years=44
44*365

2 Answers

Charles Kenney
Charles Kenney
15,604 Points

David,

You are evaluating the number of days correctly, you just aren't assign it to a variable days, as the instructions prompt you to.

Your code should look like this:

# declaring a variable `years`; assigning it to the integer 44
years = 44
# declaring a variable `days`; assigning it to the result of 365 * years
days = years * 365
# for the third part of the challenge
weeks = days / 7
Alex Koumparos
MOD
Alex Koumparos
Python Web Development Treehouse Moderator 33,475 Points

Hi David,

For this task you are being asked to do two things (on one line).

First, you are being asked to multiply the variable years by 365. What you are doing is multiplying a number literal by 365.

Then you are being asked to assign that value to a variable called days. That's just like what you did on the first line except you're assigning the calculation (strictly speaking, the calculation's result) to the variable instead of just the number.

For example, if we had a process that took 2 hours to complete and we stored that value in the variable hours we might want to express that in minutes, so we would compute the value as follows:

hours * 60

We can assign this calculation to a variable by putting the variable name and assignment operator before the calculation:

minutes = hours * 60

Hope this clears everything up for you

Cheers

Alex