13.9k views
4 votes
2.20 Write an expression involving a three-letter string s that evaluates to a string whose characters are the characters of s in reverse order. If s is 'top', the expression should evaluate to 'pot'.

User Seun Osewa
by
3.4k points

1 Answer

13 votes

Answer:

The program in Python is as follows:

s = input("Three letter string: ")

if(len(s)==3):

print(s[::-1])

else:

print("Invalid length")

Step-by-step explanation:

This prompts the user for a three-letter string

s = input("Three letter string: ")

The following if condition checks if the length of the string is 3. If yes, it reverses and print the reversed string

if(len(s)==3):

print(s[::-1])

If otherwise, it prints "Invalid length"

else:

print("Invalid length")

User Anuragsinhame
by
3.5k points