Recursive approach for palindrome
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answer ( 1 )
Via: https://www.tutorialspoint.com/python-program-to-check-whether-a-string-is-a-palindrome-or-not-using-recursion
def check_palindrome(my_str):
if len(my_str) < 1:
return True
else:
if my_str[0] == my_str[-1]:
return check_palindrome(my_str[1:-1])
else:
return False
my_string = str(input("Enter the string :"))
print("The string is ")
print(my_string)
if(check_palindrome(my_string)==True):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")