Skip to content

Commit 8a696e4

Browse files
Added a palindrome checker
1 parent 03a4251 commit 8a696e4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

maths/is_string_palindrome.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def is_string_palindrome(words: str) -> bool:
2+
"""
3+
Returns whether `num` is a palindrome or not
4+
(see for reference https://en.wikipedia.org/wiki/Palindromic_number).
5+
6+
>>> is_string_palindrome("-121")
7+
False
8+
>>> is_string_palindrome("0")
9+
True
10+
>>> is_string_palindrome("10")
11+
False
12+
>>> is_string_palindrome("11")
13+
True
14+
>>> is_string_palindrome("101")
15+
True
16+
>>> is_string_palindrome("120")
17+
False
18+
>>> is_string_palindrome(120)
19+
False
20+
>>> is_string_palindrome("madam")
21+
True
22+
>>> is_string_palindrome("racecar")
23+
True
24+
>>> is_string_palindrome("hello")
25+
False
26+
>>> is_string_palindrome("A man a plan a canal Panama")
27+
True
28+
>>> is_string_palindrome(120)
29+
False
30+
>>> is_string_palindrome("")
31+
True
32+
>>> is_string_palindrome("noon")
33+
True
34+
>>> is_string_palindrome("Was it a car or a cat I saw")
35+
True
36+
>>> is_string_palindrome("Python")
37+
False
38+
>>> is_string_palindrome(" ")
39+
True
40+
"""
41+
cleaned_phrase = ''.join(words.split()).lower()
42+
return cleaned_phrase == cleaned_phrase[::-1]
43+
44+
if __name__ == "__main__":
45+
n=input("Enter a word:-")
46+
print(is_string_palindrome(n))

0 commit comments

Comments
 (0)