Skip to content

Instantly share code, notes, and snippets.

@smanurung
Created September 19, 2019 05:46
Show Gist options
  • Save smanurung/451e3efa4310a596626f8ca4da849ddf to your computer and use it in GitHub Desktop.
Save smanurung/451e3efa4310a596626f8ca4da849ddf to your computer and use it in GitHub Desktop.
Simple palindrome code check
#!/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)))
@smanurung
Copy link
Author

Below is the execution example:

$ python sample.py 
candidate for palindrome: aza
isPalindrome(aza): True
candidate for palindrome: test
isPalindrome(test): False
candidate for palindrome: crazy
isPalindrome(crazy): False
candidate for palindrome: xanananax
isPalindrome(xanananax): True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment