# File: strstrip.py # trips off leading and/or trailing blanks # # # 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 + '"' # # now strip the white space # transstr = '"' + instr.lstrip() + '"' print("Deleting the leading white space from", prstr, "gives", transstr) transstr = '"' + instr.rstrip() + '"' print("Deleting the trailing white space from", prstr, "gives", transstr) transstr = '"' + instr.strip() + '"' print("Deleting the leading and trailing white space from", prstr, "gives", transstr)