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.

Ex: If the input is:

Hello there
Hey
quit
then the output is:

ereht olleH
yeH

I can't figure out how to make this code. If anyone could help I would appreciate it.

Respuesta :

Answer:

while True:

       values = str(input())

       if values == 'quit' or values == 'Quit' or values == 'q':

              break

       print(values[::-1])

Explanation:

Firstly, save the code on a folder and save it with any name but it must end with .py . Example data.py, save.py, reverse.py etc. Afterward, you run the code on the python shell . On the shell type  "python saved filename(save.py or data.py, reverse.py)"

I used python to solve the problem. Normally, if one wants to iterate or loop through a particular function or code you  use a loop. In this case i used a while loop.

Using while True , the values will always loop since True is always True.

values = str(input()) , This code make sure the input is always a string, since we want only text.

if values == 'quit' or values == 'Quit' or values == 'q':  , This code means the values should quit or stop working if the user input any of the text "quit" or "Quit" or "q".

print(values[::-1]) ,  This code means the input text should be reversed. example joy will be yoj

Generally, the code will always loop and print the reverse of the text unless it encounter any input value like "quit" or "Quit" or "q"

The code is in Python

It uses an indefinite while loop to keep the user entering the text and a for loop to reverse the text

Comments are used to explain each line of the code

#Create an indefinite while loop that iterates until user enters "Quit", "quit", or "q"

while True:

   #Get the input

   text = str(input())

   

   #Check if the user enters "Quit", "quit", or "q". If that is the case stop the loop using break

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

       break

   

   #Create an empty string to hold the reversed text

   reversed_text = ""

   

   #Create a for loop to iterate over the text from the end of the text

   #Append the last character to the text in each iteration

   for i in range(len(text)-1, -1, -1):

       reversed_text += text[i]

   

   #Print the reversed text

   print(reversed_text)

Here is another question related to the loops:

brainly.com/question/23419814