# 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()

Lessons Learned:

  1. Converting a list to string can be done by join. Giving space between the single quotes adds space between the texts.
  2. If you want to print all the characters in reverse order, [: : -1 ] is to be used.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s