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"
# 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)
Comments
Leave a comment