I have an assignment to write a python program that asks the user to input a single character and then checks if it is an alphabetical digit (not special characters) or a digit or neither with neither and prints what it is.
I was testing the method below out of curiosity thinking it will return an error or print Invalid input. But lo and behold it actually works perfectly but I have no idea why.
c = input("Enter a character: ")
if 'a' <= c.lower() <= 'z' and len(c) == 1: # .lower() in case the input is either capital or lowercase
print('Your character', "'" + c + "'", 'is an alphabetical letter')
elif '0' <= c <= '9' and len(c) == 1:
print('Your character', "'" + c + "'", 'is a digit')
else:
print('Invalid input')