Answer to Question #214741 in Python for Jace

Question #214741

1. 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 by word. The words must print in one line (not beneath each other). Insert spaces between the words. Example: "What is the best song right now" > "now right song best the is What" Print the sentence in reverse order - letter by letter. The words must print in one line (not beneath each other). Insert spaces between the words. # Example: "What is the best song right now" > "won thgir gnos tseb eht si tahW" 


1
Expert's answer
2021-07-07T07:53:45-0400
words=[]
while True:
    sentence=input()
    words=sentence.split(' ')
    if len(sentence)>=5:
        break
words.reverse()
for w in words:
    print(f"{w}",end=' ')
    
print(f"\n{sentence[::-1]}")





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