# File: strchcase.py # Changes case of characters in a string # # Matt Bishop, MHI 289I, Fall 2020 # 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 do the transformations # transstr = '"' + instr.capitalize() + '"' print("Capitalizing the first letter of", prstr, "gives", transstr) transstr = '"' + instr.title() + '"' print("Making", prstr, "into a title gives", transstr) transstr = '"' + instr.lower() + '"' print("Making all letters of", prstr, "lower case gives", transstr) transstr = '"' + instr.upper() + '"' print("Making all letters of", prstr, "upper case gives", transstr) transstr = '"' + instr.swapcase() + '"' print("Swapping the case of the letters in", prstr, "gives", transstr)