Palindrome? Python


#1



Traceback (most recent call last):

File "", line 1, in
is_palindrome(s)

File "E:/Python/lab7.py", line 37, in is_palindrome
while s[0] == s[-1]:

IndexError: string index out of range

Just wondering why this method for finding out whether a string s is a palindrome doesn't work? The while notation seems to be correct, may not be though


def is_palindrome(s):
    """Takes a string s and returns the value True if s is a palindrome, and
    False if not."""
    if len(s) == 0 or len(s) == 1:
        return True
    while s[0] == s[-1]:
        if len(s) == 0 or len(s) == 1:
            return True
        else:
            s = s[1:-1]
            print s
    return False


#2

you included a function call? I am unable to reproduce the error, is this of a exercise? If so, can you provide the url


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.