Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to check whether a given number is a disarium number in Python

2 Answers

0 votes
import math 

def is_disarium(num):
    remainder = 0
    len = int(math.log10(num)) + 1
    summ = 0.0
    temp = num
    
    while (temp > 0) :
        remainder = temp % 10
        summ = summ + math.pow(remainder, len)
        temp = int(temp / 10)
        len -= 1
    
    return num == int(summ)
 
 
num = 175 # 1^1+ 7^2 + 5^3 = 175

if (is_disarium(num)) :
    print(str(num) + " is a disarium number")
else:
    print(str(num) + " is not a disarium number")
 
    
    
     
     
'''
run:
     
175 is a disarium number
     
'''

 





answered Jul 24, 2021 by avibootz
edited Feb 6 by avibootz
0 votes
import math 

def is_disarium(num):
    temp = 0
    
    for i in range(len(str(num))):
        temp += int(str(num)[i]) ** (i + 1)
        
    return temp == num
 
 
num = 175 # 1^1+ 7^2 + 5^3 = 175

if (is_disarium(num)) :
    print(str(num) + " is a disarium number")
else:
    print(str(num) + " is not a disarium number")
 
  
  
    
     
     
'''
run:
     
175 is a disarium number
     
'''

 





answered Feb 6 by avibootz

Related questions

...