Homework 9: Palindrome Program
Objective: To examine a user-entered string to determine if it's a palindrome.
A palindrome is a word that is spelled the same forward and backward, such as "radar" or "madam." Your
program should ask the user to enter a word, and then tell the user whether or not that word is a
palindrome. Your program doesn't need to determine whether or not the word is in the English language.
So for example your program would determine that the word "abcdefghijjihgfedcba" is a
palindrome.
Here is some sample output from the program:
[cpersiko@fog cs110a]$ python3 palindrome.py.txt
Please enter a word: Radar
The word you entered: 'Radar' is a palindrome.
Do you want to enter another word? yes
Please enter a word: abcCBA
The word you entered: 'abcCBA' is a palindrome.
Do you want to enter another word? Y
Please enter a word: abcdecba
The word you entered: 'abcdecba' is not a palindrome.
Do you want to enter another word? n
[cpersiko@fog cs110a]$
Requirements:
- Your program should have at least 2 functions, including a main() function (no global variables or global code other than a call to main within an if-statement)
- Your program should ask the user if they want to enter another word, and if the user types "yes" or "y", upper or lower case, then the program should repeat.
- Your program should handle mixed-case input for palindromes such as shown in the above example (convert all strings to lower case in your code, to make this easy)
- Every function (except main) needs to have a comment in a triple-quoted string at the beginning, briefly explaining what it does.
- Test your program with all of the above test cases.
- As with every assignment, you must write all the code yourself. Do not copy any code other people have written. If you use any Python features we haven't covered in class then the graders will search the internet for that code, to make sure you didn't copy it from a web site.
- Make sure to put a comment at the top of your program with your name, the name of this assignment and class (110A Homework 9), and a brief description of what the program does.
- Make sure to submit your homework using Canvas.
- Remember you're required to present a program in class one time this semester. To present this one, e-mail me your solution at cpersiko@ccsf.edu and I'll let you know if you're selected to present.
For 1 point extra credit
Make your program so that it also checks for palindromic phrases: remove all punctuation and spacing, then check if it's a palindrome. For example:
[cpersiko@fog cs110a]$ python3 palindrome.py.txt
Please enter a word or phrase: No sir, away! A papaya war is on!
The text you entered: 'No sir, away! A papaya war is on!' is a palindrome.
Do you want to enter another? yes
Please enter a word or phrase: Madam In Eden, I'm Adam
The text you entered: 'Madam In Eden, I'm Adam' is a palindrome.
Do you want to enter another? No
[cpersiko@fog cs110a]$
You may want to use the "isalpha()" function and/or others described in
the Python docs for string methods.