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 trialJesse DiMauro
Courses Plus Student 937 PointsDealing 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
231,269 PointsYou were trying to convert the string "age" into an integer. It will work if you leave off the quotes 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
Courses Plus Student 937 PointsJesse DiMauro
Courses Plus Student 937 PointsAh, thank you! And thanks for that extra info as well!