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

Adam Sun
Adam Sun
198 Points

how do you use multiplication

not sure how to properly write the code to multiply my variable with an integer

age.py
variable_years = "years"
years = 30
years x 365="days"

1 Answer

Logan R
Logan R
22,989 Points

What's up!

You are sort of on the right track, but you have a few issues.

First, let's look at the first challenge: Create a variable named years. Assign years to the number of years old you are.

You successfully completed this with the code:

years = 30

The second challenge says multiply the number years by the number of days in a year.. Here, we can assume the number of days in a year is 365.

In Python, we use the * to multiply, not x like most people write when doing Math at school. Python's syntax for multiplication is as follows: "<number> * <number>", where "<number>" could be an integer (like 30), a decimal (like 3.5), or a variable (like years).

This would mean:

years = 30

print( years * 365 )

Would print out 10950. Python knows that the word "years" really means 30. From there it says "Okay, 30 times 365 is 10950. The last part of challenge 2 is to store this result in a variable called days. So instead of printing out our result, lets assign it to the word "days":

years = 30

days = years * 365

I hope this clears up your question! If not, please leave a comment to this about anything you may not be clear about and I will try my best to clear it up or someone else may come along and be able to explain it better :)

Thanks!