Palindrome

Ulrich Schramme news at u-schramme.de
Thu Nov 13 02:21:30 EST 2003


Runic911 wrote:
> Does anyone know how i can fix my Palindrome program?
> 
> s = raw_input('Enter a String: ')
> punctuation = '%$!*.,-:? ;()\'\"\\'
> i = 0
> h = 0
> t = 0
> p = ''
> z = 0
> while s!= ' ':
>     while i <= len(s) - 1:
>         punct = s[i]
>         if punctuation.find(punct) == -1:
>             p = p + punct
>         i = i + 1
>         t = p.lower()
>         t[h] == t[len(t)-1-h]


I´m not very experienced with Python but I think you could do it in a 
more simple way.


inp = raw_input('Enter a string: ')

pal = []
rev = []
for c in inp:
     if c.isalnum():
         pal.append(c.upper())
         rev.append(c.upper())
rev.reverse()
if pal == rev:
     print '"' + inp + '" ' + 'is a palindrome.'
else:
     print '"' + inp + '" ' + 'is no palindrome.'



-- 
-- Ulli
www.u-schramme.de





More information about the Python-list mailing list