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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 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, 2024 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, 2024 by avibootz

Related questions

1 answer 109 views
1 answer 124 views
1 answer 113 views
1 answer 117 views
1 answer 118 views
...