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
- Python Program to Add Two Numbers
- Python Program to Find/Calculate Sum of n Numbers
- Python Program to Find/Calculate Average of 3, 4, 5…n numbers
- Python Program to Print ASCII Value of Character
- Write a Program to Calculate Simple Interest in Python
- Python Program to Compute Compound Interest
- Leap Year Program in Python
- Python Program to Print Star Pattern
- Number Pattern Programs in Python
- Python Program to Print Even and Odd numbers From 1 to N
- Python Abs() Function: For Absolute Value
- How to Check Whether a Number is Fibonacci or Not in Python
- Python: Program to Find Power of Number
- Python Program to Reverse a Numbers
- Python Program to Find Smallest/Minimum of n Numbers
- Python Program to Find Largest/Maximum of n Numbers
- Python Program to Find The Net Bill Amount After Discount
- Python Program to Print Numbers From N to 1 and 1 to N
- Python Program to Print Numbers Divisible by 3, 5, 7
- Python Program to Print Prime Number 1 to N
- How to Find Square of Number in Python
- Python Program to Calculate Cube of Number
- Python Program to Find LCM of Two Numbers
- BMI (Body Mass Index) Calculator in Python
- Palindrome Program in Python using while loop, Function, etc
- Python: Program to Count Total Number of Bits in Number
- Python Random Number Generator Code
- Python Program to Calculate n-th term of a Fibonacci Series
- Zip Zap Zoom Python Program
- Python: program to convert Celsius to Fahrenheit
- Python Program to Swap Two Numbers
- Python Program to Get Standard Deviation
- Python Program to Find the Variance
- Python Program to Convert Height in cm to Feet and Inches
- Python Program to Convert Meters into Yards, Yards into Meters
- Python Program to Convert Kilometers to Meters, Miles
- Python Program to Find Perfect Number
- Python: Program to Find Strong Number
- Python Program Create Basic Calculator
- Python Program For math.floor() Method
- Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
- Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
- Python Program to Find Roots of Quadratic Equation
- Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
- Python Program to Check Given Input is Alphabet, Number or Special Character