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 

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 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 Best Website and Software Company in Allahabad