# File: strtype.py # Returns the number of types of characters in a string # # Matt Bishop, ECS 36A, Winter 2019 # # while True: # read in a string; quit on EOF try: instr = input("Enter a string: ") except EOFError: break except: print("Unknown error; EOF to end") continue # # put quotes around the string to show its boundaries when it is printed # prstr = '"' + instr + '"' # # now test the character types # if instr.isalpha(): print(prstr, "contains only letters") if instr.isalnum(): print(prstr, "contains only alphanumeric characters") if instr.isdigit(): print(prstr, "contains only digits") if instr.isspace(): print(prstr, "contains only white space") if instr.isupper(): print(prstr, "contains only upper case letters") if instr.islower(): print(prstr, "contains only lower case letters")