# L-8 MCS 275 Fri 29 Jan 2010 : palindromes.py # A word is a palindrome if reading forward and backward # yields the same word. def is_palindrome(x): """ returns true if x is a palindrome """ if len(x) <= 1: return True elif x[0] != x[len(x)-1]: return False elif len(x) == 2: return True else: y = x[1:len(x)-1] return is_palindrome(y) def main(): """ prompts the user for a word and checks if it is a palindrome """ w = raw_input('give a word : ') s = 'the word \"' + w + '\" is ' if not is_palindrome(w): s = s + 'not ' s = s + 'a palindrome' print s if __name__ == "__main__": main()