Tuesday, 26 April 2011

pallindrome script

I wrote the below python script to find if the string is pallindrome or not.

while True:
try:
input_string = str(input("Enter a string: "))
if input_string.isdigit():
pass
else:
break
except Exception, e:
print e
a = []
b = []
for i in input_string:
a.append(i)
a.reverse()

for i in input_string:
b.append(i)
if a == b:
print input_string, "is a pallindrome"
else:
print input_string, "is not a pallindrome"

Output:
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "elle"
elle is a pallindrome
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "malayalam"
malayalam is a pallindrome
[madhu@localhost tmp]$ python pallindrome.py
Enter a string: "pallindrome"
pallindrome is not a pallindrome

No comments:

Post a Comment