Python Program to Find Strong Number

Python program to find strong number; Through this tutorial, i am going to show you how to find strong number in python.

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

# 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

# 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

# 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

Recommended Python Tutorials

Leave a Comment