# File: strtype.py # Returns the number of types of characters in a string # # Matt Bishop, MHI 289I, Fall 2024 # # 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 + '"' print(prstr) # # now test the character types # nuttin = True if instr.isalpha(): print(prstr, "contains only letters") nuttin = False if instr.isalnum(): print(prstr, "contains only alphanumeric characters") nuttin = False if instr.isdigit(): print(prstr, "contains only digits") nuttin = False if instr.isspace(): print(prstr, "contains only white space") nuttin = False if instr.isupper(): print(prstr, "contains only upper case letters") nuttin = False if instr.islower(): print(prstr, "contains only lower case letters") nuttin = False if nuttin: print(prstr, "has a mix of letters, digits, symbols, and white space")