[Solved] Brown has been given a five-letter word by Crown, and he has been instructed to reverse it

Brown has been given a five-letter word by Crown, and he has been instructed to reverse it. If the provided word and the reversed word are the identical, Brown should respond with the word true. If not, Brown need to respond with false.

Constraints

length of the word = 5

letters of the word are case sensistive.

Sample Input 0

madam

Sample Output 0

True

Solution

Approach:

The input is taken in the variable n.

The string is reversed using the slice operator.

The reversed string is compared with the original string.

If the reversed string is equal to the original string, then the output is True.

If the reversed string is not equal to the original string, then the output is False.

n = input()
if n == n[::-1]:
    print("True")
else:
    print("False")

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *