Processing math: 0%

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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.")
# 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.")
# 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Enter a number: 89
89 is a Disarium number.
Enter a number: 89 89 is a Disarium number.
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: 195