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

Reza Nadjmabadi
Reza Nadjmabadi
632 Points

Finally, create a new variable named summary that adds the string version of days into "I am {} days old!".

I have passed the last two steps and I'm on the final step. Here is my code:

age = 25

days = (age * 7 * 52)

print (days)

summary = 365 * days

print (" I am {} days old!".format(summary) )

The error that comes out stating that I did not format it to string. So, I'm a little bit confused am I not understanding something here?

days_alive.py
age = 25 


days = (age * 7 * 52)

print (days)

summary = 365 * days 

print (" I am {} days old!".format(summary) )

5 Answers

Chris Shaw
Chris Shaw
26,662 Points

Hi Reza,

The reason this challenge isn't passing is because you have a two print statements which don't need to be there and your summary variable contains an integer instead of the formatted string, the code you want to have is as follows.

age = 25
days = age * 52 * 7
summary = 'I am {} days old!'.format(days)

Aayush Bhandari, the format method accepts both integers and strings along with other types of objects as well, you don't need to convert it as Python will infer it's type and associate it with the correct placeholder.

Happy coding!

Aayush Bhandari
Aayush Bhandari
11,224 Points

Hi Reza, the .format takes in string as arguments. The summary variable is not string, its an integer. So instead of just putting in summary inside format convert it to string first, i.e. .format(str(summary))

Reza Nadjmabadi
Reza Nadjmabadi
632 Points

the exact error is: Your summary variable should be a string!

Reza Nadjmabadi
Reza Nadjmabadi
632 Points

nvm I figured it out turns out that all i had to do was use summary = str(days)

print (" I am {} days old!".format(summary) )

Reza Nadjmabadi
Reza Nadjmabadi
632 Points

oh thank you Aayush, I didn't see your post earlier, but the information you provided why the answer is what it is helps me understand a lot better. Thank you very much sir.