Now You Code In Class: Palindrome Detector

Write a program to detect palindromes [https://en.wikipedia.org/wiki/Palindrome]. A palindrome is defined as a word or phrase which is the same in reverse. Here's some example's of one word palindromes:

dad
wow
pop
abba
noon
kayak
madam
solos
racecar

There's several ways you accomplish this but we'd recommend using Python's extended slice notation as covered in the readings. It's by far the simplest method.

The final program should take input and return whether the text is or is not a palindrome until you enter quit.

Sample run of complete program:

Enter text or type `quit`: dad
'dad' is a palindrome.
Enter text or type `quit`: pappa
'pappa' is not a palindrome.
Enter text or type `quit`: quit

Once again we will use the problem simplification technique to writing this program.

First we will write the isPalindrome(text) function, then we will write the main program.

Step 1: Problem Analysis for isPalindrome function only

Inputs:

Outputs:

Algorithm (Steps in Program):


In [ ]:
## Step 2: todo write function definition here

In [ ]:
## step 3: test the isPalindrome function to make sure it works:
print("Input:", "kayak", "Should be True, Actual Value:", isPalindrome("kayak") )
print("Input:", "mike", "Should be False, Actual Value:", isPalindrome("mike") )

Step 4: Problem Analysis for full Program

Inputs:

Outputs:

Algorithm (Steps in Program):


In [ ]:
## Step 5: todo write code for full problem, using the isPalindrome function to help you solve the problem

Step 6: Questions

  1. Did you use a loop inside your isPalindrome function? Can you think of a way to re-factor it without a loop?
  2. How many tests are required in step 3?
  3. What is the exit condition of the loop in the full program?

In [ ]: