. Advertisement .
..3..
. Advertisement .
..4..
I encounter ”typeerror: not all arguments converted during string formatting” error when I’m attempting to compare one input value to another.
Enter Your Age: 17
Traceback (most recent call last):
File "f:\Python Script\Python\2021\temp.py", line 9, in <module>
print ("Your Age is '{0}' Which is Less Than '{1}' So That You Are Not Eligible"% age, "18")
TypeError: not all arguments converted during string formatting
Here is my code:
age = input("Enter Your Age: ")
if age <= "18":
print ("Your Age is '{0}' Which is Less Than '{1}' So That You Are Not Eligible"% age, "18")
else:
print("Eligible")
What should I do with this error?
The cause: I think this error happens because you are using
{}
but you didn’t use.format
.The solution: To fix this error, you should use
.format
like the following:Now, this error has been solved. Here is the full code:
Output: