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 −


 Live Demo

my_num = 296
print("The number is")
temp = my_num
   remainder = my_num%10
   my_sum = my_sum+fact
if(my_sum == temp):
   print("The number is a strong number")
   print("The number is not a strong number")


The number is
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.