Write a recursive Python program to test if a string is a palindrome or not.

def palindrome(word,i,j):
   if(i==j):
      return 'palindrome'
   if(word[i]==word[j] and i<j):
      palindrome(word,i+1,j-1)
   else:
      return 'not palindrome'
   return 'palindrome'
 
word=input("enter word to check ")
size=len(word)
i=0
j=size-1
result=palindrome(word,i,j)
print(result)
 

Explanation: In this program we are using recursion. It can be done in simple ways also. In main program we are getting input from user to check. Size is stored in size variable. Then palindrome function is being called with three arguments.

In palindrome function we are checking if i==j, it means word is a single character. Then next we are checking if characters from both the ends of word are same or not, if characters are same and index i is less then index j function is calling itself repetitively.

Each time index position from both the ends are changed sequentially. If this condition is satisfied till whole length of word, it means word is palindrome. Otherwise function will return string ‘not palindrome’. In last we are printing result of program.