Reverse the sentence
your are given a string S as input , write a program to print the string after reversing words of the given sentence.
the first line of input is S.
in the given example the sentence "This is Python" contain 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
OUTPUT :- Python is This
SAMPLE INPUT 2
Hi! World Hello
OUTPUT:- Hello World Hi!
input_string = input()
string_split = input_string.split(" ")
string_split.reverse()
print(" ".join(string_split))
Comments
Leave a comment