Disarium Numbers in PYTHON

A Disarium Number is a special kind of number when it's sum of its digits raise to the power of their respective positions is equal to the the number itself....
Let's see some examples...
    :-175 is a Disarium Number 
       1^1+7^2+5^3=175(original one)
    :-135 is an Disarium Number
      1^1+3^2+5^3=135p
Let's see the code behind it...
--------------------####-------------------



num=int(input("Enter a number"))
dig=len(str(num))
temp=num
s=0
while temp>0:
          d=temp%10
          s=s+(d**dig)
          temp=temp//10
          dig=dig-1
if s==num:
   print("It's a Disarium Number")
else:
   print("Sorry!!! it's not")


OUTPUT

175
It's a Disarium Number
135
It's a Disarium Number
123
Sorry!!! it's not

Comments

Archive

Contact Form

Send