Python Program to Check if a Number is a Disarium Number

A Disarium number is a number in which the sum of its digits, each raised to the power of its position, equals the original number.

šŸ’” Example of a Disarium Number:

Take 89:

\[ 8^1 + 9^2 = 8 + 81 = 89 \]

Since the sum equals the original number, 89 is a Disarium number.

In this tutorial, we will write a Python program to check whether a given number is a Disarium number or not.

Python Program to Check Disarium Number

# Function to check if a number is Disarium
def is_disarium(num):
    num_str = str(num)
    length = len(num_str)
    sum_digits = sum(int(digit) ** (index + 1) for index, digit in enumerate(num_str))
    
    return sum_digits == num

# Taking user input
number = int(input("Enter a number: "))

# Checking and displaying the result
if is_disarium(number):
    print(f"{number} is a Disarium number.")
else:
    print(f"{number} is not a Disarium number.")

Output

Enter a number: 89
89 is a Disarium number.

āœ” Test Cases:

NumberCalculationDisarium?
8981 + 92 = 8 + 81 = 89 āœ… Yes
13511 + 32 + 53 = 1 + 9 + 125 = 135āœ… Yes
12311 + 22 + 33 = 1 + 4 + 27 = 32āŒ No
Share your love
Subhankar Rakshit
Subhankar Rakshit

Hey there! Iā€™m Subhankar Rakshit, the brains behind PySeek. Iā€™m a Post Graduate in Computer Science. PySeek is where I channel my love for Python programming and share it with the world through engaging and informative blogs.

Articles:Ā 212