-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.py
More file actions
23 lines (23 loc) · 828 Bytes
/
Palindrome.py
File metadata and controls
23 lines (23 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#Program to find if a string is a palindrome or not
def palindrome():
word=input('Enter a string')
if len(word)==1:
print(word,'is a palindrome')
elif len(word)%2==0:
for n in range(0,int(len(word)/2)):
if word[n]==word[len(word)-(n+1)]:
if not n==int(len(word)/2)-1:
continue
print(word,'is a palindrome')
else:
print(word,'is not a palindrome')
break
elif len(word)%2!=0:
for n in range(0,int((len(word)/2)-0.5)):
if word[n]==word[len(word)-(n+1)]:
if not n==int((len(word)/2)-0.5)-1:
continue
print(word,'is a palindrome')
else:
print(word,'is not a palindrome')
break