Plz I really need your help

I did this code to show whether if the enter sentence is palindrome or not but I am not sure what's wrong with my code ... Plz I need your feed back :icon_sad:
def pa(sentence):
    sentence = str(input("Enter your sentence: "))
    if len(sentence) < 1:
        return True
        if sentence[0] == sentence[-1]:
            return pa(sentence[1:-1])
            print("It is palindrome")
            return False
            print("It is not palindrome")


  • I normally don't answer questions in this forum, but looks to me like you have reversed lines 7 and 8 and lines 10 and 11. If the program returns on line 7 how can line 8 be executed?? same with lines 10 and 11.

    Line 7 does recursion -- calls function pa again. When it's called the second time it should ask you to enter the sentence all over again. I think you need to remove line 2 from that function and put it just before calling pa for the first time.
  • Yeah you either need a sub function to use to recurse through the string or to use a while loop with a stepper. Alternatively you can use the awesome ability of python to reverse a string like so
Sign In or Register to comment.