From 4f446d4edd386f866d3e1e4cb78715527c95720d Mon Sep 17 00:00:00 2001 From: AmruthNavaneeth Date: Thu, 13 Jun 2024 11:56:08 +0530 Subject: [PATCH] Create palindrome.py --- palindrome.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 palindrome.py diff --git a/palindrome.py b/palindrome.py new file mode 100644 index 000000000..c6aa151db --- /dev/null +++ b/palindrome.py @@ -0,0 +1,31 @@ +# Recursive function to check if a +# string is palindrome +def isPalindrome(s): + + # to change it the string is similar case + s = s.lower() + # length of s + l = len(s) + + # if length is less than 2 + if l < 2: + return True + + # If s[0] and s[l-1] are equal + elif s[0] == s[l - 1]: + + # Call is palindrome form substring(1,l-1) + return isPalindrome(s[1: l - 1]) + + else: + return False + +# Driver Code +s = "MalaYaLam" +ans = isPalindrome(s) + +if ans: + print("Yes") + +else: + print("No")