-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_palindrome.py
61 lines (46 loc) · 1.01 KB
/
check_palindrome.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Problem
-------
**Check if Palindrome**
Checks if the string entered by the user
is a palindrome. That is that it reads
the same forwards as backwards like racecar
Solution
--------
The solution is provided simply checking if the string
is equal to the same string reversed.
Author
------
dbonadiman
"""
import sys
def palindrome(s):
"""
palindrome
This function simply checks if the string
is equals to itself reversed
Parameters:
s ==> the string
Test:
>>> palindrome('racecar')
True
>>> palindrome('ciao')
False
"""
return s == s[::-1]
def main():
try:
print("\nThis program checks if a sting is palindrome\n"
"Please enter the string you want to check: \n")
string = raw_input("--> ")
print('')
print(palindrome(string))
return 0
except Exception, e:
print(e)
return 1
if __name__ == "__main__":
import doctest
doctest.testmod()
status = main()
sys.exit(status)