From da848dc318169abc3d9ea6f76ae16a19b4c07ed0 Mon Sep 17 00:00:00 2001 From: JASKAMAL SINGH <54163864+JASKAMAL22@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:27:37 +0530 Subject: [PATCH] Create is_Palindrome.py Added source code in python --- Recursion/is_Palindrome.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Recursion/is_Palindrome.py diff --git a/Recursion/is_Palindrome.py b/Recursion/is_Palindrome.py new file mode 100644 index 0000000..e85a069 --- /dev/null +++ b/Recursion/is_Palindrome.py @@ -0,0 +1,16 @@ +'''A recursive Python program to check whether a string is palindrome or not''' + +def isPalindrome(s, i): + if(i > len(s)/2): #base case + return True + ans = False + if((s[i] is s[len(s) - i - 1]) and isPalindrome(s, i + 1)): #recursive step + ans = True + return ans + +str = "racecar" +if (isPalindrome(str, 0)): + print("Yes") +else: + print("No") +