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.

Daffa Alif Pratama
2,316 PointsCannot convert to integers
Earlier in the video, Kenneth said that we can convert float to integer by using the int() function and put the floats into it e.g: int(2.54) will be converted to 2
But, when I enter decimal number when input_int being asked, it shows this error:
Traceback (most recent call last):
File "string_multiply.py", line 4, in <module>
print(input_string*int(input_int))
ValueError: invalid literal for int() with base 10: '2.54'
Does anyone has any explanation about this? Thank you! :)
2 Answers

Kevin Roundtree
4,575 PointsTry using int(floor(input_int)).

Jesse Pavlis
18,088 PointsThe issue here is that the input_int
variable is a string, not a float. Try int(float(input_int))

Daffa Alif Pratama
2,316 PointsThis error shows up:
What's ya number? 1.25
Traceback (most recent call last):
File "percent_letter.py", line 13, in <module>
print(user_string[ratio])
IndexError: string index out of range
Daffa Alif Pratama
2,316 PointsDaffa Alif Pratama
2,316 PointsThanks for the answer! But unfortunately, it gives me this error:
File "string_multiply.py", line 4, in <module> print(input_string*int(floor(input_int))) NameError: name 'floor' is not defined
Chris Freeman
Treehouse Moderator 68,154 PointsChris Freeman
Treehouse Moderator 68,154 Pointsfloor
is in themath
module. Need to add:from math import floor