Q. Write a program that reads a string and checks whether it is a palindrome string or not.

Answer :

string = input("Enter a string :")
length = len(string)
mid = int(length / 2)
rev = -1
for a in range (mid) :
    if string[a] == string[rev] :
        a += 1
        rev -= 1
    else :
        print(string, "is not a palindrome")
        break
else :
    print(string, "is a palindrome")

Output :

Enter a string : Pathwalla
Pathwalla is not a palindrome
>>>

Enter a string : madam
madam is a palindrome
>>>

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post