# Python Program to Find Strong Number

Python program to find strong number; In this tutorial, you will learn how to find whether a number is strong or not in python using for loop, while loop, and function.

## Python Program to Find Strong Number

• Python Program to find Strong Number using While Loop.
• Strong Number in Python using For Loop.
• Strong Number in Python using Function.

### Python Program to find Strong Number using While Loop

• Take input from the user.
• Using two while loops, calculate the factorial of each of the digits in the number.
• Next, sum of all the factorials of the digits.
• Use if statement To check the sum of the factorials of the digits is equal to the by user-entered number.
• Print the final result.
```# Python Program to find Strong Number using while loop

Num = int(input(" Please Enter any Number: "))
Sum = 0
Temp = Num

while(Temp > 0):
Factorial = 1
i = 1
Reminder = Temp % 10

while(i <= Reminder):
Factorial = Factorial * i
i = i + 1

print("\n Factorial of %d = %d" %(Reminder, Factorial))
Sum = Sum + Factorial
Temp = Temp // 10

print("\n Sum of Factorials of a Given Number %d = %d" %(Num, Sum))

if (Sum == Num):
print(" %d is a Strong Number" %Num)
else:
print(" %d is not a Strong Number" %Num)
```

Output

``` Please Enter any Number:  165

Factorial of 5 = 120

Factorial of 6 = 720

Factorial of 1 = 1

Sum of Factorials of a Given Number 165 = 841
165 is not a Strong Number```

### Strong Number in Python using For Loop

• Take input from the user.
• Using two For loops, calculate the factorial of each of the digits in the number.
• Next, the sum of all the factorials of the digits.
• Use if statement To check the sum of the factorials of the digits is equal to the by user-entered number.
• Print the final result.
```# Python Program to find Strong Number using for loop

Num = int(input(" Please Enter any Number: "))
Sum = 0
Temp = Num

while(Temp > 0):
Factorial = 1
Reminder = Temp % 10

for i in range(1, Reminder + 1):
Factorial = Factorial * i

print("Factorial of %d = %d" %(Reminder, Factorial))
Sum = Sum + Factorial
Temp = Temp // 10

print("\n Sum of Factorials of a Given Number %d = %d" %(Num, Sum))

if (Sum == Num):
print(" %d is a Strong Number" %Num)
else:
print(" %d is not a Strong Number" %Num)
```

Output

```Please Enter any Number:  145

Factorial of 5 = 120
Factorial of 4 = 24
Factorial of 1 = 1

Sum of Factorials of a Given Number 145 = 145
145 is a Strong Number```

### Strong Number in Python using Function.

• Take input from the user.
• Using a while loop with math factorial function, calculate the factorial of each of the digits in the number.
• Next, the sum of all the factorials of the digits.
• Use if statement To check the sum of the factorials of the digits is equal to the by user-entered number.
• Print the final result.
```# Python Program to find Strong Number using function

import math

Num = int(input(" Please Enter any Number: "))
Sum = 0
Temp = Num

while(Temp > 0):
Reminder = Temp % 10
Factorial = math.factorial(Reminder)

print("Factorial of %d = %d" %(Reminder, Factorial))
Sum = Sum + Factorial
Temp = Temp // 10

print("\n Sum of Factorials of a Given Number %d = %d" %(Num, Sum))

if (Sum == Num):
print(" %d is a Strong Number" %Num)
else:
print(" %d is not a Strong Number" %Num)
```

Output

```Please Enter any Number:  40585
Factorial of 5 = 120
Factorial of 8 = 40320
Factorial of 5 = 120
Factorial of 0 = 1
Factorial of 4 = 24

Sum of Factorials of a Given Number 40585 = 40585
40585 is a Strong Number```