A palindrome is a sentence that contains the same sequence of letters reading it either forwards or backwards. A classic example is '1\.ble was I, ereI saw Elba." Write a recursive function that detects whether a string is apalindrome. The basic idea is to check that the first and last letters of thestring are the same letter; if they are, then the entire string is a palindromeif everything between those letters is a palindrome.There are a couple of special cases to check for. If either the first orlast character of the string is not a letter, you can check to see if the restof the string is a palindrome with that character removed. Also, when youcompare letters, make sure that you do it in a case-insensitive way.Use your function in a program that prompts a user for a phrase andthen tells whether or not it is a palindrome. Here's another classic fortesting: '1\. man, a plan, a canal, Panama!"
A palindrome is a sentence that contains the same sequence of letters reading it either forwards or backwards. A classic example is '1\.ble was I, ere
I saw Elba." Write a recursive function that detects whether a string is a
palindrome. The basic idea is to check that the first and last letters of the
string are the same letter; if they are, then the entire string is a palindrome
if everything between those letters is a palindrome.
There are a couple of special cases to check for. If either the first or
last character of the string is not a letter, you can check to see if the rest
of the string is a palindrome with that character removed. Also, when you
compare letters, make sure that you do it in a case-insensitive way.
Use your function in a
then tells whether or not it is a palindrome. Here's another classic for
testing: '1\. man, a plan, a canal, Panama!"
Step by step
Solved in 4 steps with 2 images