Part of the series

Several example codes

~1 min read • Updated Sep 16, 2025

Program Overview

This Python program checks all three-digit numbers (from 100 to 999).
It prints those numbers where the sum of the factorials of their digits equals the number itself.
For example, 145 is valid because 1! + 4! + 5! = 145.


Python Code:


def factorial(n):
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

print("Three-digit numbers where the sum of digit factorials equals the number:")

for num in range(100, 1000):
    digits = [int(d) for d in str(num)]
    total = sum(factorial(d) for d in digits)
    if total == num:
        print(num)

Sample Output:


Three-digit numbers where the sum of digit factorials equals the number:
145

Explanation:

Here’s how the program works:
- The factorial() function calculates the factorial of each digit
- Each number is split into its digits using string conversion
- The sum of the digit factorials is compared to the original number
- If they match, the number is printed


Written & researched by Dr. Shahin Siami