[Tutor] Code for checking whether an input string is a palindrome or not.
Asrarahmed Kadri
ajkadri at googlemail.com
Fri Oct 13 14:03:15 CEST 2006
Hi,
Here is a code that reports whether the string is a palindrome or not. I
have posted it to help people new to programming ( i am also a newbie) to
understand the logic and comment on it.
Share and expand your knowledge as well as understanding...
Happy scripting....
Regards,
Asrar
Code:
string1 = raw_input("enter a string\n")
str_len = len(string1)
flag = 0
j = str_len-1
for i in range(0,(str_len-1)/2):
if string1[i] == string1[j]:
j = j-1
else:
flag = 1
break
if flag ==0:
print "The entered string is a PALINDROME"
else:
print "The entered string is not a PALINDROME"
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061013/c5162c3e/attachment.htm
More information about the Tutor
mailing list