- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Python Program to Check if a Number is a Strong Number
Strong number is a number whose sum of all digits’ factorial is equal to the number ‘n’. Factorial implies when we find the product of all the numbers below that number including that number and is denoted by ! (Exclamation sign), For example: 5! = 5x4x3x2x1 = 120. When it is required to check if a number is a strong number or not, the remainder/modulus operator and the ‘while’ loop can be used.
Below is the demonstration of the same −
my_sum=0 my_num = 296 print("The number is") print(my_num) temp = my_num while(my_num): i=1 fact=1 remainder = my_num%10 while(i<=remainder): fact=fact*i i=i+1 my_sum = my_sum+fact my_num=my_num//10 if(my_sum == temp): print("The number is a strong number") else: print("The number is not a strong number")
The number is 296 The number is not a strong number
A sum is initialized to 0.
The number is defined and is displayed on the console.
The number is defined to a temporary variable.
The while loop is used where the remainder is determined.
The while loop is used again to see whether the iterator is less than or equal to the remainder.
If it is less, the ‘fact’ variable is multiplied with the iterator.
It is then incremented by 1.
The sum value is added to the ‘fact’ variable.
If the ‘temp’ variable and the sum are equal, it is considered a string number.
- Related Articles
- Write a Python program to find if a number is strong number or not
- Python Program to Check if a Number is a Perfect Number
- C Program to check Strong Number
- Python program to check if the given number is a Disarium Number
- Python Program for How to check if a given number is a Fibonacci number?
- How to check if a given number is a Fibonacci number in Python Program ?
- Golang Program to Check if a Number is a Perfect Number
- Python program to check if a number is Prime or not
- Python program to check if a given string is number Palindrome
- Python program to check if the given number is Happy Number
- How To Check Whether a Number is a Strong Number or Not in Java?
- Java Program to Check if a given Number is Perfect Number
- Python Program to Check if a Number is Positive, Negative or 0
- Swift Program to Check If a Number is Spy number or not
- To Check if a Number is a Munchhausen Number