- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to check if the given number is a Disarium Number
When it is required to check if a given nmber is a disarium number, the sum of digits powered to their respective position is computed. Before this, the number of digits present in the number is determined.
A Disarium Number is the one where the sum of its digits to the power of their respective position is equal to the original number itself.
Below is a demonstration for the same −
def length_calculation(num_val): length = 0 while(num_val != 0): length = length + 1 num_val = num_val//10 return length my_num = 192 remaining = sum_val = 0 len_val = length_calculation(my_num) print("A copy of the original number is being made...") num_val = my_num while(my_num > 0): remaining = my_num%10 sum_val = sum_val + int(remaining**len_val) my_num = my_num//10 len_val = len_val - 1 if(sum_val == num_val): print(str(num_val) + " is a disarium number !") else: print(str(num_val) + " isn't a disarium number")
A copy of the original number is being made... 192 isn't a disarium number
- A method named ‘length_calculation’ is defined, that calculates the number of digits in the number.
- It computes the floor division of the number and returns the length of the number.
- The number is defined, and is displayed on the console.
- It uses the modulus operation to get the remainder, and adds it to a sum variable.
- The power of the position is multiplied with the number itself.
- This is compared with the number.
- If it is equal, it means it is a Harshad number, otherwise it is not.
- Python program to check if the given number is Happy Number
- How to check if a given number is a Fibonacci number in Python Program ?
- Python Program for How to check if a given number is a Fibonacci number?
- Python program to check if a given string is number Palindrome
- Python Program to Check if a Number is a Perfect Number
- Python Program to Check if a Number is a Strong Number
- Java Program for check if a given number is Fibonacci number?
- Check if the given number is Ore number or not in Python
- Program to check given number is a Fibonacci term in Python
- Check if given number is Emirp Number or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Golang Program to Check if a Number is a Perfect Number
- Check if a given string is a valid number in Python
- Python program to check if a number is Prime or not