-
Notifications
You must be signed in to change notification settings - Fork 3
/
IsPalindrome.py
55 lines (41 loc) · 1.13 KB
/
IsPalindrome.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
# GHC_Codepath
# Sandbox - 3
# SE101: Is Palindrome?
#!/bin/python3
import math
import os
import random
import re
import sys
# The function is expected to return an INTEGER.
# The function accepts STRING a as parameter.
# Check if a is a palindrome and return 1 if it
# is a palindrome and 0 if it is not.
def isPalindrome(a):
# since input contains spaces and non alphanumeric
# characters, we need to check that as well
# since original string can have non-alpha
# characters and upper case alpha too
new_string = ""
for i in range(len(a)):
if a[i].isalpha():
new_string += a[i].lower()
# another way:
# i = 0
# j = len(new_string) - 1
## checking the lest and right halves
# while i < j:
# if new_string[i] !=new_string[j]:
# return 0
# i += 1
# j -= 1
# return 1
if new_string == new_string[::-1]:
return 1
else: return 0
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
a = input()
result = isPalindrome(a)
fptr.write(str(result) + '\n')
fptr.close()