-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome_checker.py
executable file
·38 lines (28 loc) · 1009 Bytes
/
palindrome_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# A palindrome is a string that reads the same forward and backward, for example,
# radar, toot, and madam. This program is to check whether the input string is a
# palindrome.
class Deque:
def __init__(self, input_string):
self.deque = list(input_string)
def remove_front(self):
return self.deque.pop(0)
def remove_rear(self):
return self.deque.pop()
def size(self):
return len(self.deque)
def whether_is_a_palindrome(self):
still_equal = True
while self.size() > 1 and still_equal:
first = self.remove_front()
last = self.remove_rear()
if first != last:
still_equal = False
print still_equal
def main():
print 'This program is to check whether a word is a palindrome.'
input_string = input('Please input the word you want to check: ')
word = Deque(input_string)
word.whether_is_a_palindrome()
if __name__ == '__main__':
main()