Question #97173

In the last problem, we get an error if we enter more than one character at a time. Rewrite the program so that it only calls the ord method if a single character is entered.

Sample Run

Enter a character: *
ASCII #42

Enter a character: exit
Not a character

Expert's answer

char = input('Enter a character:')
if len(char) != 1:
    print('Not a character')
else:
    print('ASCII #{}'.format(ord(char)))
LATEST TUTORIALS
APPROVED BY CLIENTS