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

Li Chang
Li Chang
11,883 Points

Finally, create 2 new variables, one named estimate that holds the rounded number of days you've lived and, one named su

Finally, create 2 new variables, one named estimate that holds the rounded number of days you've lived and, one named summary that adds the string version of estimate into "I am {} days old!".

I am a little bit confuse this.

4 Answers

I'm not in the python track (yet) and I'm not sure what is this question for but I'll try to explain.

Two of the data types in python are integers and strings.

variable = 2 #this stores the number 2 in the variable.

variable = "2" #this stores the string 2 in the variable.

In python you have two build-in functions - int() and str().

The int() function converts what's inside the parentheses into an integer. An integer is a whole number and in rounds the number if it is with a floating point. So int(2.3) will be converted to 2.

The str() function converts what's inside the parentheses into a string. So str(2) will be converted to 2. But this is a string, not an integer. You cannot for example make addition operation like str(2) + 5. It will give you an error.

But you can make an addition operation like this int(2) + 5. The result will be 7.

So for your question.

create 2 new variables, one named estimate that holds the rounded number of days you've lived and, one named summary that adds the string version of estimate into "I am {} days old!".

lived_days = 12345.5432 #making a variable that stores the number of days you lived. I chose random number.

estimate = int(lived_days) #the variable "estimate" contains the number 12346 (rounded 12345.5432)

summary = "I am " + str(estimate) + " days old" #the variable "summary" stores the string "I am 12346 days old".

In the summary variable, you have to use the str() function because you can't concatenate strings and numbers, so you have to convert "estimate" into a string.

I hope I helped.

Good Luck!

Laurence Stokes
Laurence Stokes
6,109 Points

Well, you want to create one variable that holds the number of days you've lived as a whole number (an integer).

estimate = int(days) #estimate is now an integer representation of the floating point variable days

You then want to pass estimate to the output 'I am {(estimate)} days old!' as a string, which can be achieved by normal string concatenation means and adding the str() cast to estimate, just like we added the int() cast to days.

summary = "text you want here" + str(estimate) + "more text"

Thanks for the help guys. May be simple to some but it stumped me...