Implement the function _isPalindrome() in palindrome.py, using recursion, such that it returns True if the argument s is a palindrome (ie, reads the same forwards and backwards), and False otherwise. You may assume that s is all lower case and doesn’t include any whitespace characters.

Respuesta :

Answer:

The function is as follows:

def _isPalindrome(stri) :

  if len(stri) == 0:

     return True

  if stri[0] == stri[len(stri) - 1]:

     return _isPalindrome(stri[1:len(stri) - 1])

  else:

     return False

Explanation:

This defines the function

def _isPalindrome(stri) :

If the string is empty, then it is palindrome

  if len(stri) == 0:

     return True

This checks if the characters at alternate positions are the same.

If yes, it calls the function to check for other characters

  if stri[0] == stri[len(stri) - 1]:

     return _isPalindrome(stri[1:len(stri) - 1])

If otherwise, the string is not palindrome

  else:

     return False

ACCESS MORE
EDU ACCESS
Universidad de Mexico