Created
November 3, 2017 03:50
-
-
Save WalkerWalker/eac951c136403f8a6fa4aa17adaa6a09 to your computer and use it in GitHub Desktop.
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
# 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