Python Program to Find Strong Number

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

Recommended Python Programs

  1. Python Program to Add Two Numbers
  2. Python Program to Find/Calculate Sum of n Numbers
  3. Python Program to Find/Calculate Average of 3, 4, 5…n numbers
  4. Python Program to Print ASCII Value of Character
  5. Write a Program to Calculate Simple Interest in Python
  6. Python Program to Compute Compound Interest
  7. Leap Year Program in Python
  8. Python Program to Print Star Pattern
  9. Number Pattern Programs in Python
  10. Python Program to Print Even and Odd numbers From 1 to N
  11. Python Abs() Function: For Absolute Value
  12. How to Check Whether a Number is Fibonacci or Not in Python
  13. Python: Program to Find Power of Number
  14. Python Program to Reverse a Numbers
  15. Python Program to Find Smallest/Minimum of n Numbers
  16. Python Program to Find Largest/Maximum of n Numbers
  17. Python Program to Find The Net Bill Amount After Discount
  18. Python Program to Print Numbers From N to 1 and 1 to N
  19. Python Program to Print Numbers Divisible by 3, 5, 7
  20. Python Program to Print Prime Number 1 to N
  21. How to Find Square of Number in Python
  22. Python Program to Calculate Cube of Number
  23. Python Program to Find LCM of Two Numbers
  24. BMI (Body Mass Index) Calculator in Python
  25. Palindrome Program in Python using while loop, Function, etc
  26. Python: Program to Count Total Number of Bits in Number
  27. Python Random Number Generator Code
  28. Python Program to Calculate n-th term of a Fibonacci Series
  29. Zip Zap Zoom Python Program
  30. Python: program to convert Celsius to Fahrenheit
  31. Python Program to Swap Two Numbers
  32. Python Program to Get Standard Deviation
  33. Python Program to Find the Variance
  34. Python Program to Convert Height in cm to Feet and Inches
  35. Python Program to Convert Meters into Yards, Yards into Meters
  36. Python Program to Convert Kilometers to Meters, Miles
  37. Python Program to Find Perfect Number
  38. Python: Program to Find Strong Number
  39. Python Program Create Basic Calculator
  40. Python Program For math.floor() Method
  41. Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
  42. Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
  43. Python Program to Find Roots of Quadratic Equation
  44. Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
  45. Python Program to Check Given Input is Alphabet, Number or Special Character

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *