forked from aaqaishtyaq/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.py
More file actions
27 lines (22 loc) · 773 Bytes
/
Palindrome.py
File metadata and controls
27 lines (22 loc) · 773 Bytes
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
# An example for checking whether the string is palindrome or not
# 1st of all what the palidrome string is.
# A palindrome is a word, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar.
# Some well-known English palindromes are, "Able was I ere I saw Elba",[2] "A man, a plan, a canal – Panama",[3] "Madam, I'm Adam" and "Never odd or even".
# so here is a code
# by using for loop
x=str(input())
y=x
a=len(x)
for i in range(0,a):
if(x[i]!=y[a-i-1]):
print("Not Palindrome")
break
if(i==a-1):
print("Palindrome")
# it is by list method
x=(input())
x=list(x) # this converts x str into list
if(x==x[::-1]): # x[::-1] implies it reverse the x list
print("Palindrome")
else:
print("Not Palindrome")