• the longest palindromic

 

Why is this code not working for some test cases?

def longest_palindromic(text):
    letter = 0
    lenght= 0
    long_pal = text[0]

    while letter < len(text):

        current_string = text[letter:(lenght + 1)] 

        if current_string == current_string[::-1] and len(current_string) > len(long_pal):

            long_pal = current_string

        if lenght + 1 <= len(text[letter:]):
            lenght += 1
        else:
            letter += 1

    return long_pal