Programming Examples

Python program to reverse order of its words in given sentence


Write a Python code to accept a sentence. Display the sentence in reverse order of its words.

Sample Input: Computer is fun

Sample Output: Fun is Computer

wd="";rwd=""
str=input("Enter a string :")
str=str+" "
p=len(str)
for i in range(0,p):
    if(str[i]==" "):
        rwd=wd+" "+rwd
        wd=""
    else:
        wd=wd+str[i]
print("Words in reversed order:",rwd)
Output

Enter a string :Infomax Computer Academy

Words in reversed order: Academy Computer Infomax 

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad