Question
python 3.xx Recursion A palindrome is a word or phrase that reads the same forwards or backwards (e.g. dad, mom, deed). Write a recrusive function,
python 3.xx
Recursion
A palindrome is a word or phrase that reads the same forwards or backwards (e.g. "dad", "mom", "deed"). Write a recrusive function, isPalindrome that accepts a string and returns whether the string is a palindrome. A string is a palindrome if:
*it is an empty string or consists of a single letter, or
*if the first and last characters are the same, and the rest of the string forms a palindrome
Your function should ignore spaces and only compare letters.
'
this is what I have , works with different words or phrases like "racecar", "!", but not with "never odd or even"
def isPalindrome(string):
if len(string) <= 1: return True elif string[0] != string[len(string) - 1]: return False return isPalindrome(string[1:len(string) - 1])
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started