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 

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz