First Method:
string = input("Enter a string:")
r = ""
l = len(string)
for a in range(l):
r = r + string[l-a-1]
if(string == r):
print(string, "is a palindrome")
else:
print(string, "is not a palindrome")
Second Method:
string = input("Enter a string:")
r = ""
length = len(string)
for a in range(-1, (-length-1), -1):
r = r + string[a]
if(string == r):
print(string, "is a palindrome")
else:
print(string, "is not a palindrome")
No comments:
Post a Comment