Write a program to search palindrome number from given numbers and do addition of the digits of all palindrome numbers. - Pratik Ghelani

Pratik Ghelani

Breaking

Sunday, May 10, 2020

Write a program to search palindrome number from given numbers and do addition of the digits of all palindrome numbers.

Input:-

digit = int(input("Enter the Digit:"))
print("palindrome Number:-")
def reverse(num):
    rev = 0;
    while (num > 0):
        rev = rev * 10 + num % 10;
        num = num // 10;  
    return rev;
def isPalindrome(num): 
    if (num == reverse(num)):
        return True;
    return False;
def printPalindromes(d):
    if (d <= 0):
        return;
    smallest = pow(10, d - 1);
    largest = pow(10, d) - 1;
for i in range(smallest, largest + 1):
        if (isPalindrome(i)):
            print(i, end = " "); 

printPalindromes(digit);


Output:-


No comments:

Post a Comment