Knowee
Questions
Features
Study Tools

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 "Done", "done", or "d" for the line of text.Ex: If the input is:Hello thereHeydonethe output is:ereht olleHyeH

Question

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 "Done", "done", or "d" for the line of text.Ex: If the input is:Hello thereHeydonethe output is:ereht olleHyeH

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that fulfills your requirements:

while True:
    text = input("Enter a line of text (or 'Done', 'done', 'd' to quit): ")
    if text.lower() in ['done', 'd']:
        break
    else:
        print(text[::-1])

This program works as follows:

  1. It enters an infinite loop with while True.
  2. It asks the user to input a line of text.
  3. If the user enters "Done", "done", or "d", the program breaks out of the loop and ends.
  4. If the user enters anything else, the program prints the reverse of the input text using text[::-1], which is a Python slice that steps backwards through the string.

This problem has been solved

Similar Questions

Design a program such that it converts a sentence into wordlist. Reverse the wordlist then. Write the code and output for the same.

python program to reverse a string

Write a Python program that repeatedly reads lines from standard input until anEOFError is raised, and then outputs those lines in reverse order

Write a program in C to print a string in reverse using a character pointer. Also print the uppercase of the first letter of the reversed word. Sample Input word Sample Output drow D

Write a program that takes a string of lowercase characters as input and prints it in uppercase, reversed.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.