# string transformations # # first, a comparison function # def same_str(str1, str2, print1): if str1 == str2: print(print1, "are the same") else: print(print1, "are not the same") # # now the fun begins! # # read in the strings first = input("String 1: ") second = input("String 2: ") # # see if they are the same # print("Checking in main . . . ", end='') if first == second: print("The strings are the same") else: print("The strings are not the same") input("Press ENTER to continue> ") print("Checking in a function . . . ", end='') same_str(first, second, "The strings") input("Press ENTER to continue> ") # # now try them in upper case # ufirst = first.upper() usecond = second.upper() print("The first string in upper case is", ufirst) print("The second string in upper case is", usecond) same_str(ufirst, usecond, "The strings in upper case") # # lower case; the comparison should be the same as above # lfirst = first.lower() lsecond = second.lower() print("The first string in lower case is", lfirst) print("The second string in lower case is", lsecond) same_str(lfirst, lsecond, "The strings in lower case") # # swap case; the comparison should be the same as above # sfirst = first.swapcase() ssecond = second.swapcase() print("The first string with case swapped is", sfirst) print("The second string with case swapped is", ssecond) same_str(sfirst, ssecond, "The strings with cases swapped") # # now replace all e's with x's in the first strng, and a's with x's in the second # rfirst = first.replace('e', 'x') rsecond = second.replace('a', 'x') print("The first string with e's replaced by x's is", rfirst) print("The second string with a's replaced by x's is", rsecond) same_str(rfirst, rsecond, "The strings with e's and a's replaced by x's")