starting to learn coding. I want my program to ask the user their age and then classify them, I understand that input() always receives a string value, so I have to convert it. I thought I could do it just once at the beginning, like this:
print ('Enter your age:')
age = input ()
int(age)
and then just compare the age value with other int values:
if age <18:
print ('Underage')
elif age >= 18 and age <30:
print ('young')
But I keep getting this error: TypeError: '<' not supported between instances of 'str' and 'int'
It is fixed by doing this:
print ('Enter your age:')
age = input ()
if int(age) <18:
print ('Underage')
elif int(age) >= 18 and int(age) <30:
print ('young')
But I wanted to know if there is a way not to repeat the same over and over.
Thank you :)