Strong Number Check
Check if number is strong (sum of factorial of digits equals number).
IntermediatePhase 2 - Level 2: Number-based Looping LogicExample 12 of 14
strong-number-check.py
1# Helper function for factorial2def factorial(n):3 if n == 0 or n == 1:4 return 15 return n * factorial(n - 1)67# Take number8num = int(input("Enter a number: "))910# Calculate sum of factorial of digits11temp = abs(num)12strong_sum = 013while temp > 0:14 digit = temp % 1015 strong_sum += factorial(digit)16 temp //= 101718# Check19if abs(num) == strong_sum:20 print("Strong number")21else:22 print("Not a strong number")
Output
Enter a number: 145 Strong number
What's going on
Sum of factorial of digits equals the number.
Key Concepts:
Calculate factorial of each digit
Sum all factorials
Compare with original number
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum