+2 votes

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")

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

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

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")

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

+2 votes

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().

the solution is that you could use float(input()) instead of int(input().

0 votes

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

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

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".

...