Solve “ValueError: invalid literal for int() with base 10” in Python Neeraj Mishra The Crazy Programmer
Hello everyone, So today we’re going to see the possible reasons and solutions for the error “ ValueError: invalid literal for int() with base 10 ” in Python. The main reason for this error is that in our program, we’re passing a non-integer value to a place where the interpreter expects an integer value. To understand the above lines, let’s take an example. age = int(input("Enter your age: ")) When you run the above line, the interpreter will ask you to enter your age, when you will enter the age in numbers this program will be executed successfully, but if you’ll enter some string like “Twenty three” then it will throw the error “ ValueError: Invalid literal for int() with base 10 ”. Because input() function returns a string and outside input() function we’re trying to convert the string into an integer using int(). So the string should be convertible to int, just like a number without any spaces. But when we pass the string that contains characters or spaces it will