python - pythone 3.3.2 age >= 24: TypeError: unorderable types: str() >= int() -
print("how old you") age = input(">") if age >= 24: print("you getting old") print (age) else: print("i don't care") print (age)
this error getting:
if age >= 24: typeerror: unorderable types: str() >= int()
on python 3, input()
always returns string value. use int()
type convert it:
if int(age) >= 24:
a string value , int not orderable:
>>> '24' > 23 traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: unorderable types: str() > int()
note int()
can throw valueerror
exception, if input cannot converted:
>>> int('why want know age?') traceback (most recent call last): file "<stdin>", line 1, in <module> valueerror: invalid literal int() base 10: 'why want know age?'
Comments
Post a Comment