Write a Python program to print all Disarium numbers between 1 and 100.

In [2]:
def calculate_length(n):
    length = 0
    while n != 0:
        length = length + 1
        n = n // 10
    return length


# sum_of_digits() will calculates the sum of digits powered with their respective position
def sum_of_digits(num):
    remainder = result = 0
    length = calculate_length(num)
    while num > 0:
        remainder = num % 10
        result = result + (remainder ** length)
        num = num // 10
        length = length - 1
    return result


def print_disarium():
    result = 0
    # Displays all disarium numbers between 1 and 100
    print("Disarium numbers between 1 and 100 are")
    for i in range(1, 101):
        result = sum_of_digits(i)
        if result == i:
            print(i)


if __name__ == "__main__":
    print_disarium()
Disarium numbers between 1 and 100 are
1
2
3
4
5
6
7
8
9
89