Error guide · TypeError
TypeError: '>' not supported between instances of 'str' and 'int'
You compared text with a number.
Example
age = input() if age > 17: print("adult")
With the program input: 18
What Python says
TypeError: '>' not supported between instances of 'str' and 'int'
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
input() always returns text, even when the user types digits. Python can compare two numbers, and it can compare two pieces of text alphabetically, but it will not compare text with a number. Convert the input to a number first.
How to fix it
age = int(input()) if age > 17: print("adult")
Output: adult
Tips
- Use
int(input())for whole numbers andfloat(input())for decimals. - The same error appears with
<,>=and<=. - If the user might type something that is not a number, catch
ValueErrorwithtryandexcept.