Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

invalid literal for int() with base 10?

+2 votes
asked Oct 2, 2019 by maxr00m (170 points)
No errors when entering rounded figures for (rate), but when running the below with rate of 35.25, the error message come up (invalid literal for int() with base 10)

==================================

rate = input("Please Enter the Desired Rate ")
if int(rate) > 50:
    print("The Rate is High")
elif int(rate) < 50:
    print("The Rate is Low")
else:
    print("Exactly 50")

=================================

5 Answers

+1 vote
answered Oct 3, 2019 by anonymous
use double . always use double for currency .
+2 votes
answered Oct 5, 2019 by anonymous
This error because python is expecting an integer value ie. in simple number without any decimal,

the solution is that you could use float(input()) instead of int(input().
0 votes
answered Oct 9, 2019 by anonymous
Expecting an int.

Either typecast or use a float, double, real
0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
rate = float(input("Please Enter the Desired Rate "))
if (rate) > 50:
    print("The Rate is High")
elif (rate) < 50:
    print("The Rate is Low")
else:
    print("Exactly 50")
    

output

Please Enter the Desired Rate 50.36
The Rate is High

the mistake u did is yoar taking a float number not a simple number

for both it will work
0 votes
answered Mar 1, 2021 by geverwills (140 points)

The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that's not an integer to the int() function . In other words it's either empty, or has a character in it other than a digit. You can solve this error by using Python isdigit() method to check whether the value is number or not. The returns True if all the characters are digits, otherwise False . 

if val.isdigit():

The other way to overcome this issue is to wrap your code inside a Python try...except block to handle this error.

Python2.x and Python3.x

Sometimes the difference between Python2.x and Python3.x that leads to this ValueError: invalid literal for int() with base 10 . With Python2.x , int(str(3/2)) gives you "1". With Python3.x , the same gives you ("1.5"): ValueError: invalid literal for int() with base 10: "1.5".

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...