Created
February 13, 2018 08:47
-
-
Save MohanSha/695ce1c1c69fccdc747a8cf02a1aa22d to your computer and use it in GitHub Desktop.
Checks if the string entered by the user is a palindrome. That is that it reads the same forwards as backwards like “racecar”
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if Palindrome | |
# Checks if the string entered by the user is a palindrome. | |
# That is that it reads the same forwards as backwards like “racecar” | |
def is_palindrome(string): | |
if len(string) <= 1: | |
return True | |
if string[0] != string[-1]: | |
return False | |
return is_palindrome(string[1:-1]) | |
def is_palindrome_alt(string): | |
return string == string[::-1] | |
string = raw_input('String: ').lower() | |
if is_palindrome_alt(string): | |
print string + ' is a palindrome' | |
else: | |
print string + ' is not a palindrome' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment