Check Strong Number in Python
Check whether a number is a strong number (sum of factorials of digits).
BeginnerConditional ProgramsExample 9 of 20
check-strong-number.py
1# Program to check strong number23import math45num = int(input("Enter an integer: "))67total = 08temp = num9while temp > 0:10 digit = temp % 1011 total += math.factorial(digit)12 temp //= 101314if total == num:15 print(num, "is a strong number")16else:17 print(num, "is not a strong number")
Output
Enter an integer: 145 145 is a strong number
What's going on
A strong number equals the sum of factorials of its digits (e.g., 145 = 1! + 4! + 5!).
We extract digits with modulo and integer division, summing factorials.
After this program
If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.