3. Disarium Number
A number is said to be Disarium if the sum of its digits raised to their respective positions is the number itself.
Example:
75
7^1+5^2=7+25=32 → False
135
1^1+3^2+5^3=1^9+125=135 → True
Print True if a number is a Disarium, otherwise print False.
Input
The Input will be any integer
135
Output
True
Source code
N=int(input("Enter an integer: "))
str_n=str(N)
sum_n=0
for i in range(1,(len(str_n)+1)):
n=int(str_n[i-1])
sum_n+=n**i
if sum_n==N:
print("True")
else:
print("False")
Sample output 1
Sample output 2
Comments
Leave a comment