185k views
2 votes
Write a program that takes in a line of text as input and outputs that line of text in reverse.

User Valla
by
6.4k points

1 Answer

6 votes

Answer:

Here is one possible implementation of a program that takes a line of text as input and outputs the line in reverse:

# Get input from the user

line = input("Enter a line of text: ")

# Reverse the line of text using the slicing technique

# with a step of -1 to go through the string backwards

reversedLine = line[::-1]

# Print the reversed line of text

print(reversedLine)

Here is an example of how this program might be used:

Enter a line of text: Hello, world!

!dlrow ,olleH

User Mr Squid
by
5.8k points