Answer to Question #225785 in Python for Siva

Question #225785

You are given a string S as input, write a program to print the string after reversing the words of the given sentence.


Input

The first line of input is a string S.


Explanation

In the given example, the sentence This is Python contains 3 words. When reversing, the word Python comes to the starting of the sentence, and This goes to the last of the sentence. The word is remains in the same position.


So the output should be Python is This.


Sample Input 1

This is Python

Sample Output 1

Python is This

Sample Input 2

Hi! World Hello

Sample Output 2

Hello World Hi!



1
Expert's answer
2021-08-13T16:14:08-0400
def reversesSentence(s):
    words = s.split(' ')
    reverse_s = ' '.join(reversed(words))
    return reverse_s


if __name__ == "__main__":
    sentence=input()
    print(reversesSentence(sentence))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS