Write a program that asks the user for one or more sentences and then lets the user know if it is a palindrome.
* [ ] Blank slate
* [ ] Create a GitHub repo called `palindromic`
* [ ] Put a `README.md` file in it and copy palindrome.py and palindrome_test.py from this repository into it.
* [ ] Normal Mode
* [ ] Write your `main()` function to ask the user for a word/sentence, pass it into the is_palindrome function, and state whether or not the the sentence is palindromic
* [ ] Write your `is_palindrome` function **using recursion**
* [ ] Run palindrome_test.py and ensure you pass all the tests
* [ ] Hard Mode (optional)
* [ ] Make an iterative version of your `is_palindrome` function (using loops instead of recursion), and ensure it passes the tests too
After completing this assignment, you should understand:
- Manipulating strings
- How strings are related to lists
- Recursion
After completing this assignment, you should be able to:
- Strip characters out of strings
- Change the case of strings
- Look at substrings
- A GitHub repo called palindrome containing at least:
- This
README.md
file - a file called
palindrome.py
- This
- Your program must pass my tests in
palindrome_test.py
. You should be able to run this withpython palindrome_test.py
. - You need a function called
is_palindrome
that takes a string and returns a boolean (True
orFalse
). Your program should use this function.
You have to write a program that, when run, asks the user to input some text. It can be a phrase, a sentence, or multiple sentences. After it is entered, your program will let the user know if it is a palindrome or not. Use "is a palindrome" and "is not a palindrome" in your output in order for the tests to pass.
Letter casing and punctuation do not matter when testing a palindrome. All of the following are valid palindromes:
- stunt nuts
- Lisa Bonet ate no basil.
- A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal: Panama!
- Doc, note, I dissent. A fast never prevents a fatness. I diet on cod.
Make both an iterative and recursive version of your palindrome test function.
You may want to use the re.sub
function to strip out punctuation and spaces. A regular expression you can use to match all space and punctuation is r'[^A-Za-z]'
.