A simple interactive Python program that checks whether a word is a palindrome or finds palindromic words within a sentence. The program runs in the terminal and allows repeated checks without restarting.
- Check if a single word is a palindrome
- Scan a sentence and detect all palindromic words
- Case-insensitive comparisons
- Ignores punctuation in sentence checks
- User-friendly input validation using
pyinputplus - Option to rerun the program indefinitely until the user exits
A palindrome is a word that reads the same forwards and backwards.
Examples:
- racecar
- level
- madam
- Python 3.x
- pyinputplus module
Install the required dependency with:
pip install pyinputplus
- Save the script as
palindrome_checker.py - Open a terminal in the same directory
- Run:
python palindrome_checker.py
- Prompts the user to enter a word
- Converts it to lowercase
- Reverses the word using slicing
- Compares the original and reversed word
- Prompts the user to enter a sentence
- Converts it to lowercase
- Removes punctuation
- Splits the sentence into words
- Identifies and lists palindromic words
- User selects:
- [1] Check a word
- [2] Check a sentence
- Program performs the selected check
- User is asked whether they want to run another check
- Program continues until the user chooses to exit
Check a [1] Word or [2] Sentence? 1
What word would you like to check? racecar
The word "racecar" is a palindrome!
This project is open-source and free to use for learning or personal projects.