Skip to content

Instantly share code, notes, and snippets.

@WalkerWalker
Created November 3, 2017 03:50
Show Gist options
  • Save WalkerWalker/eac951c136403f8a6fa4aa17adaa6a09 to your computer and use it in GitHub Desktop.
Save WalkerWalker/eac951c136403f8a6fa4aa17adaa6a09 to your computer and use it in GitHub Desktop.
# Define a procedure is_palindrome, that takes as input a string, and returns a
# Boolean indicating if the input string is a palindrome. A palindrome is a string that is the same backwards and forwards. For example, “dad”, “malayalam”, and “wow” are examples of palindromes.
def is_palindrome(s):
s_length = len(s)
pos = 0
while pos <= len(s)/2:
if s[pos] = s[s_length-pos]:
pos + 1
else:
return False
print is_palindrome('abab')
#>>> False
print is_palindrome('abba')
#>>> True
print is_palindrome('')
#>>> True
print is_palindrome('abcba')
#>>> True
print is_palindrome('abca')
#>>> False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment