Python Recursive Function Check Palindrom String
# Write a Python program to # input a string and find # whether the string is a palindrome or not # www.easycodebook.com # Start of the Python program # define the recursive function def is_palindrome(s): if len(s) <= 1: # Base case return True elif s[0] != s[len(s) - 1]: # Base case return False else: return is_palindrome(s[1 : len(s)-1]) # display message to enter string # and get input string str1 = input("Enter a string to check for palindrome:") # call the reursive function result = is_palindrome(str1) # now print if string is palindrome or not if result==True: print(str1, " is a palindrome") else: print(str1, " is a not a palindrome")
Enter a string to check for palindrome:mom mom is a palindrome Output 2: Enter a string to check for palindrome:Python Python is a not a palindrome
You may also like:
- C Program GCD By Recursion
- C Program Sum of One to N by Recursion
- C Program Sum of Digits by Recursion
- C Program Reverse Number by Recursion
- C Program Fibonacci Series by Recursion
- C Program Power By Recursion
- C Program Find Factorial by Recursion
Pingback: Python User Defined and Built-in Functions - Defining and Using Functions | EasyCodeBook.com