Suppose we have a number n. We have to check whether we can create an alphabetical lowercase string from that number and check whether the string is palindrome or not. Here we will take only characters from a to j, [a = 0, b = 1... j = 9]. So if the number is 42 the substring "ec" will be printed till 6 (4+2) characters "ececec" then check this is palindrome or not.
So, if the input is like n = 43, then the output will be True the string is "ededede" and this is palindrome.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def isPalindrome(s): return s == s[::-1] def solve(n): temp = "" s = str(n) letters = "abcdefghij" sum = 0 substr = "" for i in range(len(s)) : d = int(s[i]) substr += letters[d] sum += d while len(temp) <= sum: temp += substr temp = temp[:sum] return isPalindrome(temp) n = 43 print (solve(n))