Product SiteDocumentation Site

8.4. Palindrome പരിശോധിക്കല്‍

Palindrome are the kind of strings which are same from left or right whichever way you read them. Example "madam". In this example we will take the word as input from the user and say if it is palindrome or not.

#!/usr/bin/env python
s = raw_input("Please enter a string: ")
z = [x for x in s]
z.reverse()
if s == "".join(z):
    print "The string is a palindrome"
else:
    print "The string is not a palindrome"

ഔട്ട്പുട്ട്

[kd@kdlappy book]$ ./palindrome.py
Please enter a string: madam1
The string is not a palindrome
[kd@kdlappy book]$ ./palindrome.py
Please enter a string: madam
The string is a palindrome