Strong Numbers in Range
Print all strong numbers in a given range.
BeginnerTopic: Loop Programs
Python Strong Numbers in Range Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to print strong numbers in a range
import math
start = int(input("Enter start of range: "))
end = int(input("Enter end of range: "))
for num in range(start, end + 1):
total = 0
temp = num
while temp > 0:
digit = temp % 10
total += math.factorial(digit)
temp //= 10
if total == num:
print(num)Output
Enter start of range: 1 Enter end of range: 500 1 2 145
Understanding Strong Numbers in Range
We reuse the strong-number definition for every number in the range and print matches.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.