close

[Solved] ValueError: invalid literal for int () with base 10

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ValueError: invalid literal for int () with base 10 in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ValueError: invalid literal for int () with base 10 Error Occurs?

Today I get the following error ValueError: invalid literal for int () with base 10 in python.

How To Solve ValueError: invalid literal for int () with base 10 Error ?

  1. How To Solve ValueError: invalid literal for int () with base 10 Error ?

    To Solve ValueError: invalid literal for int () with base 10 Error I found a work around. Python will convert the number to a float. Simply calling float first then converting that to an int will work: output = int(float(input))

  2. ValueError: invalid literal for int () with base 10

    To Solve ValueError: invalid literal for int () with base 10 Error I found a work around. Python will convert the number to a float. Simply calling float first then converting that to an int will work: output = int(float(input))

Solution 1

Just for the record:

>>> int('55063.000000')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '55063.000000'

Got me here…

>>> int(float('55063.000000'))
55063

Has to be used!

Solution 2

I found a work around. Python will convert the number to a float. Simply calling float first then converting that to an int will work: output = int(float(input))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read