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 (Retired) Things That Count Things That Count

I followed the instructions to the best of my knowledge and I have no idea what to do!

I am confused as to how to include the variable days into my code.

days_alive.py
age = int("30")
days = int (age *52 *7)
summary = str("I am" + days(int) ys old!")

2 Answers

Hi Alaina,

Whenever you need to assign a number to a variable you can do so directly. You don't have to make it a string literal first and then convert to an integer.

Example:

age = 30

You can do the same for days. Just do the calculation and the result will already be an integer.

For the 3rd task it's probably easiest to solve it using the format() method.

If I wanted to create the string "I am 30 years old" as an example you could do it like this:

summary = "I am {} years old".format(age)

In this example, the curly braces will be replaced with whatever the value of age is.

Like Jason said... You don't have to typecast your variables. So:

age = 30

is fine. The last line, you omitted a quote.

summary = "I am" + days +  "yrs old!"

Again, no need for the explicit type conversions. Python is smart enough to figure that out.

You do have to convert days to a string if using string concatenation. Also, you're not allowing for spaces around days