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!
def reversesSentence(s):
words = s.split(' ')
reverse_s = ' '.join(reversed(words))
return reverse_s
if __name__ == "__main__":
sentence=input()
print(reversesSentence(sentence))
Comments
Leave a comment