Answer to Question #214802 in Python for Maya

Question #214802

Write a python program that prompts the user to enter a sentence of at least 5 words. Include a test to ensure that the user has entered at least 5 words. Store the individual words as separate items in a list. Print the sentence in reverse order - word for word. The word must print in one line (not beneath each other) and spaces must be inserted between the words. The sentence must be printed in reverse order example: "Where is the mountain" - "niatnuom eht si erehW"


1
Expert's answer
2021-07-07T18:20:59-0400
# Write a python program that prompts the user to enter a
# sentence of at least 5 words. Include a test to ensure that
# the user has entered at least 5 words. Store the individual
# words as separate items in a list. Print the sentence in reverse order - word for word.
# The word must print in one line (not beneath each other) and spaces
# must be inserted between the words. The sentence must be printed
# in reverse order example: "Where is the mountain" - "niatnuom eht si erehW"


sentence = ""
while(len(sentence)<5):
    sentence = str(input("Enter a sentence of minimum 5 words: ")).split(" ")
Word=[]
for r in range(0,len(sentence)):
    temp = sentence[r][::-1]
    Word.append(temp)


Word = Word[::-1]
print("Input Sentence  : ",sentence)
print("Reverse Sentence: ",Word)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS