Guest User

Untitled

a guest
Feb 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. # Check if Palindrome
  2. # Checks if the string entered by the user is a palindrome.
  3. # That is that it reads the same forwards as backwards like “racecar”
  4.  
  5.  
  6. def is_palindrome(string):
  7. if len(string) <= 1:
  8. return True
  9. if string[0] != string[-1]:
  10. return False
  11. return is_palindrome(string[1:-1])
  12.  
  13.  
  14. def is_palindrome_alt(string):
  15. return string == string[::-1]
  16.  
  17. string = raw_input('String: ').lower()
  18.  
  19. if is_palindrome_alt(string):
  20. print string + ' is a palindrome'
  21. else:
  22. print string + ' is not a palindrome'
Add Comment
Please, Sign In to add comment