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 (Retired) Things That Count Basic Numbers

Cannot 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
Kevin Roundtree
4,575 Points

Try using int(floor(input_int)).

Thanks 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
Chris Freeman
Treehouse Moderator 68,441 Points

floor is in the math module. Need to add:

from math import floor
Jesse Pavlis
Jesse Pavlis
18,088 Points

The issue here is that the input_int variable is a string, not a float. Try int(float(input_int))

This 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