Recursive approach for palindrome

Question

Write a program to find out if a string is palindrome or not, using recursion.

in progress 0
YashikaKhurana 55 years 1 Answer 698 views Master 0

Answer ( 1 )

  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")

Leave an answer

Browse
Browse