#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. def main(): print("""Type a word or fraze to see if it can reverse Hit just "Enter" to exit""" ) while True: i = input("Word: ").lower() if i: if is_palindrome(i): print("Yes:", i[::-1], "==", i) else: print("No:", i[::-1], "!=", i) else: break def is_palindrome(word): """Simple test, check if the reverse is the same Works for anything that supports slicing (object[::-1]) >>> is_palindrome("racecar") True >>> is_palindrome("cars") False >>> is_palindrome(["r", "a", "c", "e", "c", "a", "r"]) True """ if word[::-1] == word: return True else: return False if __name__ == "__main__": main()