Program to reverse the input phrase using Python

Introduction

In section our task is to reverse the input phrase.

Program to reverse the input phrase

Program

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

Output

Program to reverse the input phrase Output

Explanation

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.

Author

  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.