Created
September 19, 2019 05:46
-
-
Save smanurung/451e3efa4310a596626f8ca4da849ddf to your computer and use it in GitHub Desktop.
Simple palindrome code check
This file contains hidden or 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
#!/Users/smanurung/miniconda3/bin/python | |
class Person: | |
name = "foo" | |
def sayName(self): | |
return self.name | |
def setName(self, n): | |
self.name = n | |
class Candidate: | |
cand = '' | |
def isPalindrome(self, s): | |
str = list(s) | |
l = 0 | |
r = len(str) - 1 | |
while l <= r: | |
if str[l] == str[r]: | |
l += 1 | |
r -= 1 | |
else: | |
return False | |
return True | |
if __name__ == "__main__": | |
p = Person() | |
# print(p.sayName()) | |
p.setName("Harrison") | |
# print(p.sayName()) | |
c = Candidate() | |
# print(c.isPalindrome()) | |
while True: | |
x = input("candidate for palindrome: ") | |
print("isPalindrome({}): {}".format(x, c.isPalindrome(x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Below is the execution example: