Table of Contents
In section our task is to reverse the input phrase.
def phrase_reverse(phrase): # Split words ele = phrase.split(' ') # Reverse string and join rev = ' '.join(reversed(ele)) return rev input_string = input("Enter the phrase to reverse: \n") print(phrase_reverse(input_string))
To achieve our task we have firstly split each word from the input phrase using split() function and then joined the reversed words using spaces. The reversed phrase is stored in variable rev and printed on the screen.