
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can we generate Strong numbers in Python?
To print Strong Numbers, let's first look at the definition of it. It is a number that is the sum of factorials of its own digits. For example, 145 is a Strong number. First, create a function to calculate factorial:
def fact(num): def factorial(n): num = 1 while n >= 1: num = num * n n = n - 1 return num
You can print these numbers by running the following code:
def factorial(n): num = 1 while n >= 1: num = num * n n = n - 1 return num def print_strong_nums(start, end): for i in range(start, end + 1): # Get the digits from the number in a list: digits = list(map(int, str(i))) total = 0 for d in digits: total += factorial(d) if total == i: print(i) print_strong_nums(1, 380)
This will give the output:
1 2 145
- Related Articles
- How can we generate the same sequence of random numbers in MySQL?
- How can we use complex numbers in Python?
- How to generate armstrong numbers in Python?
- How does Python generate random numbers?
- How to generate a strong password using PowerShell?
- How to generate prime numbers using Python?
- Generate pseudo-random numbers in Python
- How to generate non-repeating random numbers in Python?
- How can we generate radiation such as gamma radiation?
- How to generate pyramid of numbers using Python?
- How can we do the basic print formatting for Python numbers?
- How can we unpack a string of integers to complex numbers in Python?
- How can we validate decimal numbers in JavaScript?
- How to use Python Numpy to generate Random Numbers?
- Program to count number of words we can generate from matrix of letters in Python

Advertisements