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 Numbers

Jesse DiMauro
PLUS
Jesse DiMauro
Courses Plus Student 937 Points

Dealing with variables and integers.

I was following the video and playing around with variables. I set age equal to 20, multiplied it by 10 and divided it by 10, giving me a float of 20.0. That raised an interesting question, could I turn the variable back into an integer? I tried 'int("age")' but got back "ValueError: invalid literal for int() with base 10: 'age'". Purely for curiosity, how would you go about turning the variable back to an integer?

1 Answer

Steven Parker
Steven Parker
231,236 Points

You were trying to convert the string "age" into an integer. It will work if you leave off the quotes :point_right: int(age)

You could also keep it from becoming a float to start with if you use integer division ("age //= 10") instead of regular division.

Jesse DiMauro
Jesse DiMauro
Courses Plus Student 937 Points

Ah, thank you! And thanks for that extra info as well!