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