Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Strong Number in Python

Strong Number in Python

Posted on February 8, 2025February 8, 2025 By Rishabh saini No Comments on Strong Number in Python

Strong Number in Python

Introduction

In this tutorial, we will learn how to determine whether a given number is a Strong Number using Python. A strong number is a unique kind of number in which the total of its digits’ factorials equals the number.

Complete Python Course with Advance topics:-Click here

What is a Strong Number?

When the sum of the factorials of a number’s digits equals the number itself, the number is said to be strong.

Example:

Consider the number 145:

  • 1! = 1
  • 4! = 24
  • 5! = 120
  • Sum of factorials: 1 + 24 + 120 = 145

145 is a strong number since the sum equals the initial value.

Problem Approach

To determine whether a given number is a Strong Number, follow these steps:

  1. Request that the user enter a number.
  2. Extract each digit from the number.
  3. Compute the factorial of each digit.
  4. Sum up all the factorials.
  5. Verify that the total equals the initial amount.
  6. Print the result.

Sample Input and Output

Input:

num = 132

Output:

Given number is not a strong number.

Input:

num = 145

Output:

Given number is a strong number.

Python Program to Find Strong Number

Let’s implement the logic using a while loop.

Example 1: Using While Loop

# A program that determines whether a given number is a strong number

sum = 0  
num = int(input("Enter a number: "))  
temp = num  

while num > 0:  
    i = 1  
    fact = 1  
    rem = num % 10  
    
    while i <= rem:  
        fact *= i   # Compute factorial  
        i += 1  
    
    sum += fact  
    num //= 10  

if sum == temp:  
    print("Given number is a Strong Number")  
else:  
    print("Given number is not a Strong Number")  

Output:

Enter a number: 145
Given number is a Strong Number.

Strong Number in Python

Explanation of the Code

  1. The user inputs a number.
  2. The sum variable is initialized to store the sum of factorials.
  3. A copy of the number is stored in temp.
  4. The while loop extracts each digit and calculates its factorial.
  5. The sum of factorials is compared with the original number.
  6. If they are equal, the number is a Strong Number, otherwise, it is not.

Alternative Approaches

Example 2: Using a For Loop

We can replace the while loop with a for loop for a cleaner approach.

# Python program to find Strong Number using for loop  
num = int(input("Enter the Number: "))  
sum = 0  
temp = num  
  
while temp > 0:  
    fact = 1  
    rem = temp % 10  
  
    for i in range(1, rem + 1):  
        fact *= i  
    
    print(f"Factorial of {rem} = {fact}")  
    sum += fact  
    temp //= 10  
  
print(f"\nSum of Factorials of {num} = {sum}")  
  
if sum == num:  
    print("The given number is a Strong Number")  
else:  
    print("The given number is not a Strong Number")  

Output:

Enter the Number: 145
Factorial of 5 = 120
Factorial of 4 = 24
Factorial of 1 = 1
Sum of Factorials of 145 = 145
The given number is a Strong Number

Example 3: Making Use of the Factorial Function in Python

To simplify the factorial calculation, we can use the math.factorial() function from Python’s math module.

import math  
num = int(input("Enter the Number: "))  
sum = 0  
temp = num  
  
while temp > 0:  
    rem = temp % 10  
    fact = math.factorial(rem)  # Using built-in factorial() function  
    print(f"Factorial of {rem} = {fact}")  
    sum += fact  
    temp //= 10  
  
print(f"\nSum of Factorials of {num} = {sum}")  
  
if sum == num:  
    print("The given number is a Strong Number")  
else:  
    print("The given number is not a Strong Number")  

Output:

Enter the Number: 145
Factorial of 5 = 120
Factorial of 4 = 24
Factorial of 1 = 1

Sum of Factorials of 145 = 145
The given number is a Strong Number.

Explanation

  • The factorial was computed using the math.factorial() function.
  • The loop keeps going until every digit has been handled.
  • To ascertain whether the total is a strong number, it is compared to the original number.

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

In this tutorial, we explored Strong Numbers and implemented different approaches using while loop, for loop, and math.factorial() function. The concept of Strong Numbers helps in understanding the use of loops, conditional statements, and factorial calculations in Python.

If you’re interested in more such tutorials, stay connected with UpdateGadh for more programming insights!


strong number in python using for loop
armstrong number in python
strong number in python example
perfect number in python
strong number in python using while loop
strong number in python using function
what is strong number
strong number example
strong number in python
program for strong number in python
check strong number in python
program to check strong number in python

Post Views: 508
Python Interview Question Tags:armstrong number in python, check strong number in python, checkout strong number in python, how to check strong number, how to check strong number in python, Python, python program for strong number, python program to check strong number, strong number, strong number in python, strong number in python hindi, strong number in python using while loop, strong number program, strong number program in python, strong numbers in python

Post navigation

Previous Post: SQL ORDER BY Clause: Sorting Data in a Structured Manner
Next Post: SQL ORDER BY Clause with Ascending Order

More Related Articles

How to Sort a Dictionary in Python How to Sort a Dictionary in Python Python Interview Question
Binary Search in Python Binary Search in Python Python Interview Question
Declare a Variable in Python How to Declare a Variable in Python Python Interview Question

Leave a Reply Cancel reply

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

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Append Elements to a List in Python
  4. How to Clear the Python Shell
  5. How to Print Patterns in Python
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,210)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,862)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme