Write a recursive function, is_palindrome() to find out whether a string is a palindrome or not. The function should return true, if it is a palindrome. Else it should return false.

Source Code:-

#PF-Assgn-40
def is_palindrome(word):
word=word.lower()
if(len(word)==1):
return True
elif(len(word)==2):
if(word[0]==word[1]):
return True
else:
return False
elif(len(word)>2 and word[0]==word[-1]):
word=word[1:-1]
result=is_palindrome(word)
if(result):
return True
else:
return False
else:
return False
#Remove pass and write your logic here
#Provide different values for word and test your program
result=is_palindrome("mm")
if(result):
print("The given word is a Palindrome")
else:
print("The given word is not a Palindrome")
view raw #PF-Assgn-40.py hosted with ❤ by GitHub

No comments:

Post a Comment

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...