Python Program to Check Whether a Number is Strong or Not

This python program checks whether a given integer number by user is Strong Number or not.

Strong numbers are those numbers whose sum of factorial of each digits is equal to the original number.

Strong Number Examples: 1 is strong number because 1!=1, 2 is strong number i.e. 2! = 2, 145 is strong number i.e. 1! + 4! + 5! = 1 + 24 + 120 = 145 etc.

List of Strong Numbers: 1, 2, 145, 40585, ...

Try: Check Strong Number Online & Generate Strong Numbers Online

Python Source Code: Strong Number


# Python program to check Strong Number

# function to find factorial
def fact(n):
    f = 1

    for i in range(1,n+1):
        f *= i

    return f


# function to check strong
def check_strong(n):
    number_copy = n
    strong_sum = 0

    while n:
        remainder = n%10
        strong_sum += fact(remainder)
        n //= 10

    return strong_sum == number_copy

# Reading number
number = int(input('Enter number: '))

# Making decision
if check_strong(number):
    print('%d is STRONG.' %(number))
else:
    print('%d is NOT STRONG.' %(number))

Strong Number Python Output

Run 1:
----------------
Enter number: 145
145 is STRONG.

Run 2:
----------------
Enter number: 123
123 is NOT STRONG.