12.4k views
2 votes
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text python

User Peshmerge
by
4.0k points

1 Answer

3 votes

Answer:

while True:

text = input("Input line of text: ")

if text == "Quit" or text == "quit" or text == "q":

print("End of the program")

break

reverseText = text[-1::-1]

print('The reverse text is: ', reverseText)

Step-by-step explanation:

We created a while loop that ask for the user input, the process repeats until the user enters "Quit" or "quit" or "q" (see the if statement), to reverse the text we use text[-1::-1], because string are arrays we use array manipulation to reverse the text, the first -1 represents the the last item in the string, :: means all the array and the last -1 represent to go through the array one by one in reverse order.

Write a program that takes in a line of text as input, and outputs that line of text-example-1