Pure Programmer
Blue Matrix


Cluster Map

Project: Starter

A [[palindrome]] is a word or phrase that is spelled the same when it is reversed. Write two functions that test a supplied string to see if it is a palindrome and return a boolean result. Ignore both case and punctuation. Writing a function to remove punctuation and convert to all lowercase would be helpful.

The first function should use recursion by checking the first and last characters to see if they are the same. If they are, pass the string, minus these characters, to the function again. Continue until there is one or no characters left.

The second function should not use recursion but only iteration to compute the same result.

Write a test program to test each function with the following to see if both produce the same results.

  • Hannah
  • Able was I ere I saw Elba
  • A man, a plan, a canal – Panama
  • T. Eliot, top bard, notes putrid tang emanating, is sad; I'd assign it a name: gnat dirt upset on drab pot toilet.
  • This is not a palindrome!

Output
$ python3 Palindrome.py Test Case: Hannah palindromeRecursive: Yes palindromeIterative: Yes Test Case: Able was I ere I saw Elba palindromeRecursive: Yes palindromeIterative: Yes Test Case: A man, a plan, a canal – Panama palindromeRecursive: Yes palindromeIterative: Yes Test Case: T. Eliot, top bard, notes putrid tang emanating, is sad; I'd assign it a name: gnat dirt upset on drab pot toilet. palindromeRecursive: Yes palindromeIterative: Yes Test Case: This is not a palindrome! palindromeRecursive: No palindromeIterative: No

Solution