Archive for April 4, 2021

Python Project: Disarium Number

April 4, 2021 1 comment

Learning : Python to solve Mathematics Problems
Subject: Disarium Number

In Mathematics there are some formulas or let say rules that generate a sequence of given a certen result, and accordingly we gave that number or that sequence a name, such as even numbers, odd numbers, prime numbers and so on.

Here in this post we will talk about the Disarium Number and will write a code to check if a given number Disarium or Not.
Defenition: A Number is a Disarium if the Sum of its digits powered with their respective position is equal to the original number. Example: If we have 25 as a Number we will say: if (2^1 + 5^2) = 25 then 25 is Disarium.
So: 2^1 = 2, 5^2 = 25, 2+25 = 27; 25 NOT Equal to 27 then 25 is NOT Disarium.

Let’s take n = 175:
1^1 = 1
7^2 = 49
5^3 = 125
(1 + 49 + 125) = 175 thats EQUAL to n so 175 is a Disarium Number.

In the bellow code, we will write a function to take a number from the user the check if it is a Disarium Number or not. In this function we will print out the calculation on the screen. Let’s start by writing the function

# is_disarium function.
def is_disarium(num) :
Project Name: Disarium Number
By: Ali Radwani
Date: 2.4.2021

the_sum = []
l = len(num)
for x in range (0,l):
print(num[x] , '^',x+1,'=', (int(num[x])**(x+1)))

if int(num) == sum(the_sum) :
print ("\n The sum is {}, and the original Number is {} So {} is a Disarium Number.".format(sum(the_sum),num,num))
print ('\n The sum is {}, and the original Number is {} So it is NOT Disarium.'.format(sum(the_sum),num))

num = input('\n Enter a Number to check if it is Disarium. > ')

# Call the function and pass the num.
ali radwani python project learning sql codeing

To Download my Python code (.py) files Click-Here

Follow me on Twitter..

By: Ali Radwani