# Write a program that asks the user for a long string containing # multiple words. # Print back to the user the same string, # except with the words in backwards order. def inputstring(): testing = input("Enter a string: ") a = len(testing) printwordsback(a, testing) def printwordsback(a, testing): if a > 1: listing = testing.split() for i in range(a + 1): set1 = listing[::-1] print(' '.join(set1)) break inputstring()
- Converting a list to string can be done by join. Giving space between the single quotes adds space between the texts.
- If you want to print all the characters in reverse order, [: : -1 ] is to be used.