Here is a quick Python coding puzzle or brain teaser for educational and/or entertainment purposes. The challenge is quite simple but is useful for learning or refreshing your coding skills while exercising some logical thinking.
Objective
Write a Python program that takes an input from the user (a word or a phrase) and tells the user if the input is a Palindrome. A palindrome reads the same forward and backward. It can be a single word or a sentence or any string. Punctuations should not be considered (i.e. ignored). Do some basic input validation for blank input, for example.
Try to solve it yourself first. Good luck! If you’re stuck, the solution code along with the ability to run the solution code right from here is provided below (scroll down).
One possible solution is below. Click Run icon on the widget below to try it out. You can click Run after each sesssion to rerun it; the code is shown side-by-side. The code also shows an example Palindrome word or a phrase (“randomly”) when the input is either blank or ‘?’.
I hope this was educational and fun. Happy coding!
For more brain teasers and puzzles, click here.