Palindroma

From Sistemi Operativi
Revision as of 14:23, 28 October 2013 by Renzo (talk | contribs)
Jump to navigation Jump to search

Visto che qui non succede nulla, inizio io:

Ecco una implementazione in python3... chi mi propone altre soluzioni alternative?

#!/usr/bin/env python3

def palindrome(x):
  if len(x) < 2: return True
  else:
    if x[0] == x[-1]:
      return palindrome(x[1:-1])
    else:
      return False

if __name__ == "__main__":
  s=input("type in a string: ")
  print("is {} palindrome? {}".format(s,"true" if palindrome(s) else "false"))