67.7k views
5 votes
develop a python program to check whether a given number is palindrome or not andalso count the number of occurrences of each digit in the input number.

User Staelen
by
7.9k points

1 Answer

5 votes

Final answer:

The Python program for checking if a number is a palindrome and counting digit occurrences defines two functions: one to check the palindrome property and another to count digit frequencies in the input number.

Step-by-step explanation:

The correct answer is that this programming task involves writing a Python script to check if a given number is a palindrome, and count the occurrences of each digit within that number. A palindrome is a number that reads the same backward as forward, like 121 or 12321. To check for a palindrome, we can convert the number to a string and compare it with its reverse.

For counting digit occurrences, we can iterate through the number's string representation and use a dictionary to keep track of each digit's count.

Example Python Program:

def is_palindrome(number):
return str(number) == str(number)[::-1]

def count_digit_occurrences(number):
digit_count = {}
for digit in str(number):
digit_count[digit] = digit_count.get(digit, 0) + 1
return digit_count

# Example usage:
number = int(input("Enter a number: "))
print("Palindrome:" if is_palindrome(number) else "Not a palindrome.")
print("Digit occurrences:", count_digit_occurrences(number))

This program defines two functions: is_palindrome to check if the number is a palindrome and count_digit_occurrences to count the number of times each digit appears.

User Nitheesh George
by
8.5k points